Skip to main contentSkip to solution

If there is a nested loop and also a single loop, then the time complexity will be estimated on the basis of the _______ loop only.

Solution

✅ Correct Option: 1

The nested loop runs about n×nn \times n times, while the single loop runs only about nn times. In Big-O notation only the term that grows fastest is kept, so the nested loop decides the complexity.

O(n2+n)=O(n2)O(n^2 + n) = \boxed{O(n^2)}


Option 2: the single loop gives O(n)O(n), which is smaller than O(n2)O(n^2) for large nn, so it is dropped.

Options 3 and 4: the order in which loops appear in the code does not matter; only the loop with the highest growth rate counts.

Keyboard Shortcuts

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