Practice question · Select all that apply
Select every requirement a loop invariant must satisfy to prove an algorithm correct.
Hints
- The three genuine obligations mirror the three parts of an induction.
- Running samples is testing, not proof; not crashing is not the same as being correct.
Show the answer
- B. Each iteration preserves the invariant.
- C. The invariant already holds when execution reaches the loop for the first time.
- E. The invariant plus the exit condition gives the desired result.
Why
Initialization, maintenance, and a useful termination condition are the three requirements. Running samples and 'never errors' are neither necessary nor sufficient, the whole point is that reasoning, not testing, shows correctness.
Practise Loop Invariants and Correctness Ideas
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.