Definition:
The Halting Problem is a fundamental question in computer science: “Given any computer program and its input, can we write another program that determines whether the first program will eventually stop running (halt) or run forever (infinite loop)?”
The answer is NO - it’s mathematically impossible to create such a universal “halt detector.”
Example:
- Program A:
count = 1
while count <= 10:
print(count)
count += 1
This clearly halts after printing 1-10.
- Program B:
while True:
print("Hello")
This obviously runs forever.
- Program C:
n = 3
while n != 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
This is the famous Collatz conjecture - mathematicians still don’t know if it halts for all starting numbers.
Why It Matters
- Software testing: We can’t automatically detect all infinite loops
- Theoretical limits: Some problems are fundamentally unsolvable
- AI safety: We can’t predict if an AI system will behave as expected in all cases