Think & Reflect · Q1
Q.What will happen if an algorithm does not stop after a finite number of steps?
Puducherry TnboardTextbookSubjective· 2mImportance★★★★★est
44% · 16/36 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →An algorithm must terminate after a finite number of steps; if it doesn't, it never delivers a result, hogs the machine's resources, and strictly speaking is not an algorithm at all — this is the infinite loop problem.
The idea. Among the defining characteristics of an algorithm (precision, unambiguity, well-defined inputs/outputs, finiteness), finiteness is the one this question probes. The whole point of an algorithm is to reach the solution; a process that never stops never reaches it.
What actually happens if the steps never end:
- No result is ever produced. The output statement after the loop is never reached, so the problem remains unsolved no matter how long you wait.
- Resources are wasted. The program keeps the CPU busy doing useless repetitions (and may keep allocating memory), which can slow down or hang the whole system.
- External intervention is needed. The user or operating system must forcibly terminate the program (for example, interrupting it from the keyboard or ending the task).
- Formally, it is not an algorithm. Finiteness is part of the definition — an endless procedure is just a non-terminating process.
A concrete non-terminating example:
i = 1
while i <= 5:
print(i) # forgot: i = i + 1
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.