Home › Interview Questions › What is the time complexity of an algorithm that d…

What is the time complexity of an algorithm that does not use a nested loop but iterates over the data once?

🟢 Easy Conceptual Fresher level
1Times asked
Oct 2026Last seen
Oct 2026First seen

💡 Model Answer

The time complexity of an algorithm that processes each element of a collection exactly once and performs only constant‑time operations inside the loop is linear, O(n). In the scenario described, there is no nested loop or recursive call that would multiply the work by another factor. The single loop iterates n times, where n is the number of items in the input. Inside the loop, the work done—such as a comparison, an arithmetic operation, or a dictionary lookup—is O(1) on average. Therefore, the total amount of work scales proportionally with the size of the input. If the input size doubles, the runtime roughly doubles, assuming the underlying data structures remain efficient. This linear time complexity is the best you can achieve for problems that require examining every element at least once, such as searching for a particular value or computing a running sum. Thus, the algorithm runs in O(n) time.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500