A loop within a loop will have the time complexity as ____ .
A loop within a loop will have the time complexity as ____ .
Solution
✅ Correct Option: 3
In a nested loop, the inner loop runs completely for every single iteration of the outer loop. If both loops run times, the total number of executions is .
For example, for i in 1..n { for j in 1..n { ... } } executes the inner body times, so the time complexity is .
Option 2: is the complexity of a single loop, not a loop within a loop.
Note that this holds when both loops depend on . If the inner loop runs a fixed number of times, the result is only .
Related questions:
2026: 11 May Shift 2
2026: 13 May Shift 2
2026: 29 May Shift 1