What will be the running time complexity of an algorithm that does not have any loop?
What will be the running time complexity of an algorithm that does not have any loop?
Solution
✅ Correct Option: 1
An algorithm with no loop (and no recursion) executes each statement a fixed number of times, whatever the input size . Its running time therefore does not grow with , so it is constant, written .
Options 2, 3 and 4: , and come from one loop, two nested loops and three nested loops respectively.
Recursion can also make an algorithm take more than constant time without any explicit loop, so the answer holds only when there is neither a loop nor recursion.
Related questions:
2025: 16 May Shift 1
2025: 27 May Shift 2
2026: 21 May Shift 1
2026: 23 May Shift 2