Step 2: Prove Correctness

Does this actually work?

Lemma: If BUBBLE terminates, A is sorted.

This follows pretty easily from the definition of ``sorted'' in terms of adjacent elements.

But does it terminate?

Need to prove that every iteration of the ``while'' loop results in measurable progress to the goal.

What can we use to measure progress?


next up previous
Next: Measures of Sortedness Up: BUBBLESORT Previous: Explanation