0

For a loop where the such function aFunction() inside the loop has a big-o of O(nlog(n)), how do you determine the worst case time complexity?

i ← 0
while (i < n)
   aFunction(...)
   i ← i+1
done
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
babygoalie29
  • 23
  • 1
  • 3
  • 1
    What are the arguments, do they depend on anything like `i` or `n`? Your code sample is too thin – Leeor Jan 15 '15 at 23:01
  • This appears to be off-topic as it deals with algorithmic time-complexity and no actual code is involved. Consider cs.stackexchange.com instead. – dg99 Jan 15 '15 at 23:11

1 Answers1

4

Think about how much total work is being done here. Each call to aFunction takes time O(n log n) and you're calling it a total of n times. Overall, that makes for a total of O(n2 log n) total work.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • Not such simple. Each call takes `O(i log i)`. So to make sure you are right we have to sum all `i log i` from i=1 to n. (If i understood OP's question correctly) – Everv0id Jan 15 '15 at 23:04
  • @Everv0id From the provided pseudocode I couldn't tell if `aFunction` was being called on `i` or on `n` on each iteration. I assumed it was `n`, but you're right that if it's `i` on each iteration there's more math required here. – templatetypedef Jan 16 '15 at 00:31