Home > Back-end > How to calculate the average time complexity in the book?
How to calculate the average time complexity in the book?
Time:11-02
The book says, because all the complexity, so the column, in a linear table, for example,) The linear table time complexity: Best case: O (1) The worst: O (n) Average: O (n/2) And then give the average time complexity is O (n).
I thought that the average time complexity is, on average, the complexity of the cases, but it is O (n). The result is only consider the worst case time complexity, or otherwise it method, (PS: take the name of the average time complexity is really easy confused,)
CodePudding user response:
For the time complexity of n/2 and n times are 1 so can be seen as n Like the n + 1 and n - 1 as a n is a truth The highest time shall prevail