5

One code I've done follows this schema:

for (i = 0; i < N; i++){ // O(N)
    //do some processing...
}

sort(array, array + N); // O(N log N)

Whats the complexity in Big-O notation?

Thanks in advance

  • Well, yes. nlog n grows stronger than n, so it dominates the overall growth. – nhahtdh Sep 14 '13 at 00:07
  • 4
    You would be able to answer this question yourself if you go back and review the definition of big-O. Now, if you go back and are still stuck, then we can lead you in the right direction. – Dennis Meng Sep 14 '13 at 00:08

1 Answers1

11

From what I understand of big-O,

O(x+y) = O(max(x,y))

Therefore,

O(n + n log n) = O(n log n)
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
  • And just to be clear, O notation doesn't tell you how absolutely fast something is, just what to expect as `n` gets really really big. – Mark Ransom Sep 14 '13 at 03:19
  • Proof of the Big-O sum rule: http://stackoverflow.com/questions/16749784/proving-big-o-sum-rule/16750079#16750079 – Imre Kerr Sep 14 '13 at 21:14
  • So for regular dfs algorithm using adjacency list time complexity is O(v+E) will be equal to O(E)? – Ayyappa Gollu Feb 10 '23 at 10:57