Time complexity analysis. choosing operator for counting number of times a line of code runs
- 阅读更多 关于 Time complexity analysis. choosing operator for counting number of times a line of code runs
问题 Analysing time complexity of this pseudocode. On the right my take on the number of times each line runs. I'm not sure whether to use log n , n log n , or simply n for the while-loop..please help times 1 sum = 0 1 2 i = 1 1 3 while i ≤ n log n + 1 4 for j = 1 to n n log n 5 sum = sum + j n log n 6 i = 2i log n 7 return sum 1 this results in: 2 n log + 2log n + 4 and thereby : O(n log n) is this correct ? 回答1: If your while loop is: 3 while i < n log n + 1 4 for j = 1 to n n log n 5 sum = sum