In a competition, four different functions are observed. All the functions use a single for loop and within the for loop, same set of statements are executed. Consider the following for loops:
If n is the size of input(positive), which function is most efficient(if the task to be performed is not an issue)?
Explanation: The time complexity of first for loop is O(n).
The time complexity of second for loop is O(n/2), equivalent to O(n) in asymptotic analysis.
The time complexity of third for loop is O(logn).
The fourth for loop doesn’t terminate.
Quiz of this Question
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.