Skip to main contentSkip to solution

Any algorithm that does not have a loop will have time complexity as ____.

Solution

✅ Correct Option: 2

Without a loop, every statement runs a fixed number of times, whatever the input size nn. The running time is therefore constant, written O(1)O(1).


Option 3: time complexity is never 00, because even a single statement takes some constant time to execute.

Options 1 and 4: O(n)O(n) comes from a loop running nn times, and O(log⁡n)O(\log n) from a loop that halves or doubles its counter each step. Both need a loop.

A loop-free algorithm can still be slower than O(1)O(1) if it uses recursion, but the question assumes simple straight-line code.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question