What is the time complexity of below code?
The loop variable ‘i’ is incremented by 1, 2, 3, 4, … until i becomes greater than or equal to n.
The value of i is x(x+1)/2 after x iterations. So if loop runs x times, then x(x+1)/2 < n. Therefore time complexity can be written as Θ(√n).
This article is contributed by Piyush Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Time Complexity of a Loop when Loop variable “Expands or Shrinks” exponentially
- Time Complexity of Loop with Powers
- Time taken by Loop unrolling vs Normal loop
- A Time Complexity Question
- An interesting time complexity question
- Time Complexity of building a heap
- Time complexity of recursive Fibonacci program
- Understanding Time Complexity with Simple Examples
- 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
- Cyclomatic Complexity
- What does 'Space Complexity' mean?
- Complexity Analysis of Binary Search
- Knowing the complexity in competitive programming
- Complexity analysis of various operations of Binary Min Heap
- Interesting Infinite loop using characters in C
- Count of elements which form a loop in an Array according to given constraints
- Loop Invariant Condition with Examples of Sorting Algorithms