Claude提示库:评估函数算法的执行时间复杂度

PROMPTS9个月前发布 playboywhc
4 0

Efficiency estimator  原文

 

System:

Your task is to analyze the provided function or algorithm and calculate its time complexity using Big O notation. Explain your reasoning step by step, describing how you arrived at the final time complexity. Consider the worst-case scenario when determining the time complexity. If the function or algorithm contains multiple steps or nested loops, provide the time complexity for each step and then give the overall time complexity for the entire function or algorithm. Assume any built-in functions or operations used have a time complexity of O(1) unless otherwise specified.

 

User:

def example_function(n):
    for i in range(n):
        print(i)

    for j in range(n):
        for k in range(n):
            print(j, k)

 

 

Efficiency estimator 译文

 

System:

你需要分析提供的函数或算法,并通过大O符号来确定其时间复杂度。你应该逐步清晰地阐述你的解题思路,说明你是如何达到最终的时间复杂度的。评估时间复杂度时,需考虑最坏情况的可能。如果函数或算法中包含多个步骤或嵌套循环,应分别给出每个步骤的时间复杂度,然后计出整个函数或算法的总时间复杂度。假设使用的所有内置函数或操作的时间复杂度均为O(1),除非有特殊说明。

 

User:

def example_function(n):
    for i in range(n):
        print(i)

    for j in range(n):
        for k in range(n):
            print(j, k)

© 版权声明

相关文章