What is the time complexity of below function?
Time complexity of above function can be written as 1k + 2k + 3k + … n1k.
Let us try few examples:
k=1 Sum = 1 + 2 + 3 ... n = n(n+1)/2 = n2 + n/2 k=2 Sum = 12 + 22 + 32 + ... n12. = n(n+1)(2n+1)/6 = n3/3 + n2/2 + n/6 k=3 Sum = 13 + 23 + 33 + ... n13. = n2(n+1)2/4 = n4/4 + n3/2 + n2/4
In general, asymptotic value can be written as (nk+1)/(k+1) + Θ(nk)
Note that, in asymptotic notations like Θ we can always ignore lower order terms. So the time complexity is Θ(nk+1 / (k+1))
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Time Complexity of a Loop when Loop variable “Expands or Shrinks” exponentially
- Time Complexity where loop variable is incremented by 1, 2, 3, 4 ..
- Performance of loops (A caching question)
- An interesting time complexity question
- Analysis of Algorithm | Set 5 (Amortized Analysis Introduction)
- Commonly Asked Data Structure Interview Questions | Set 1
- Analysis of Algorithm | Set 4 (Solving Recurrences)
- Analysis of Algorithms | Set 4 (Analysis of Loops)
- Analysis of Algorithms | Set 3 (Asymptotic Notations)
- NP-Completeness | Set 1 (Introduction)
- Analysis of Algorithms | Set 2 (Worst, Average and Best Cases)
- Analysis of Algorithms | Set 1 (Asymptotic Analysis)
- A Time Complexity Question
- What does 'Space Complexity' mean?
- Time Complexity of building a heap