What is the time complexity of the 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/2 + 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)
If n>=k then the time complexity will be considered in O((nk+1)/(k+1)) and if n<k, then the time complexity will be considered as in the O(nk)
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Time Complexity of a Loop when Loop variable “Expands or Shrinks” exponentially
- Time Complexity where loop variable is incremented by 1, 2, 3, 4 ..
- Time taken by Loop unrolling vs Normal loop
- Time Complexity of building a heap
- An interesting time complexity question
- Understanding Time Complexity with Simple Examples
- Time complexity of recursive Fibonacci program
- Practice Questions on Time Complexity Analysis
- Time Complexity Analysis | Tower Of Hanoi (Recursion)
- Python Code for time Complexity plot of Heap Sort
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- How is the time complexity of Sieve of Eratosthenes is n*log(log(n))?
- A Time Complexity Question
- What does 'Space Complexity' mean?
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Knowing the complexity in competitive programming
- Cyclomatic Complexity
- Complexity Analysis of Binary Search
- Complexity analysis of various operations of Binary Min Heap
- Loop Invariant Condition with Examples of Sorting Algorithms