Skip to main contentSkip to solution

Any algorithm that has a loop (usually 1 to n) will have the time complexity as ________.

Solution

✅ Correct Option: 1

A simple loop that runs from 1 to nn executes its body once for each value, so the work grows in direct proportion to nn. Its time complexity is O(n)O(n), called linear time.


Option 2: n2n^2 comes from a loop nested inside another loop, each running up to nn.

Option 3: log⁡(n)\log(n) comes from a loop whose counter is multiplied or divided by a constant each time (for example i=i×2i = i \times 2), not one that increases by 1.

Option 4: nlog⁡(n)n\log(n) comes from a loop of nn steps that does log⁡(n)\log(n) work in each step, as in merge sort.

Keyboard Shortcuts

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