Question:

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.

Show Hint

In asymptotic analysis, always look for the most expensive operation or the deepest loop hierarchy.
The overall Big-O of sequential tasks is simply the maximum of their individual complexities:
\[ O(f(n) + g(n)) = O(\max(f(n), g(n))) \]
Updated On: Jun 11, 2026
  • nested
  • single
  • first
  • second
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Question:

The question asks how to determine the overall asymptotic time complexity (Big-O) of an algorithm that consists of a nested loop block and a sequential single loop block running consecutively.

Step 2: Rules of Asymptotic Dominance:

- When evaluating the running time of sequential blocks of code, we sum their individual complexities:
\[ T(n) = T_1(n) + T_2(n) \]
- In Big-O notation, we focus on the dominant term (the highest-order term) as $n$ grows very large, dropping all lower-order terms and constant coefficients.

Step 3: Detailed Explanation:

- Let us analyze the complexity of the two blocks:
- Single Loop: A simple loop iterating $n$ times has a time complexity of $O(n)$.
- Nested Loop: A loop of $n$ iterations containing another loop of $n$ iterations has a time complexity of $O(n \times n) = O(n^2)$.
- Since these two loops execute one after the other, the total time expression is:
\[ T(n) = O(n^2) + O(n) \]
- As $n \to \infty$, the $n^2$ term grows much faster than the $n$ term. Therefore, the $n$ term becomes insignificant.
- Applying the dominance rule, the lower-order term $O(n)$ is dropped, leaving:
\[ T(n) \approx O(n^2) \]
- Thus, the overall complexity of the algorithm is dominated and estimated solely on the basis of the nested loop block.

Step 4: Final Answer:

The overall time complexity is determined by the highest-order term, which comes from the nested loop.
Hence, option (A) is the correct choice.
Was this answer helpful?
0
0