For such cases, time complexity of the loop is O(log(log(n))).The following cases analyse different aspects of the problem.
Case 1 :
In this case, i takes values 2, 2k, (2k)k = 2k2, (2k2)k = 2k3, …, 2klogk(log(n)). The last term must be less than or equal to n, and we have 2klogk(log(n)) = 2log(n) = n, which completely agrees with the value of our last term. So there are in total logk(log(n)) many iterations, and each iteration takes a constant amount of time to run, therefore the total time complexity is O(log(log(n))).
Case 2 :
In this case, i takes values n, n1/k, (n1/k)1/k = n1/k2, n1/k3, …, n1/klogk(log(n)), so there are in total logk(log(n)) iterations and each iteration takes time O(1), so the total time complexity is O(log(log(n))).
Refer below article for analysis of different types of loops.
This article is contributed by Rishav Raj. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
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 where loop variable is incremented by 1, 2, 3, 4 ..
- Time Complexity of Loop with Powers
- Time taken by Loop unrolling vs Normal loop
- Time Complexity of building a heap
- An interesting time complexity question
- 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
- A Time Complexity Question
- Understanding Time Complexity with Simple Examples
- 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
- Count of elements which form a loop in an Array according to given constraints