Skip to main contentSkip to solution

A loop within a loop will have the time complexity as __________.

Solution

✅ Correct Option: 1

If the outer loop runs nn times and, for every pass, the inner loop also runs nn times, the inner statement executes n×nn \times n times.

T(n)=n×n=n2T(n) = n \times n = \boxed{n^2}


Option 2: log⁡(n)\log(n) comes from a single loop where the counter is doubled or halved each time, not from nesting.

Option 3: nn is the time for a single loop.

Option 4: n3n^3 needs three nested loops, each running nn times.

Keyboard Shortcuts

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