Skip to content
Advertisement

Analysis of run time complexity

I need some help below I have some code I created for an assignment. I am having a hard time figuring out the time complexity of this algorithm. I looked at it and believe the O-notation is 0(n) and the function is F(n)= 4 + 2n. But I think that is incorrect.

JavaScript

Advertisement

Answer

Just wanted to point out that Arrays.sort itself is O(n logn). If we ignore that, the loop takes linear time.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement