Lecture 08 Ticket Solution
Complete before the beginning of class on Monday, 09/19.
Download this ticket in pdf format or .tex source.
Give an argument that every (correct) sorting algorithm requires
Hint. What can you say about an algorithm that uses
Solution
Intuitively, any algorithm that sorts arrays must at the very least access (and potentially modify) the entire array. Since each
Formal Argument by Contrapositive
We can make this argument more formal by constructing an explicit sequence of inputs that require
Claim. Sorting
This claim may seem “obvious,” but we will formally prove it using a technique called “proof by contrapositive.” The idea is as follows. Our claim can be rephrased as,
- If an algorithm
sorts , then uses at least s.
This statement is logically equivalent to the statement
- If
uses fewer than s, then does not sort .
The second claim is known as the contrapositive of the first claim. Since the two original claim and its contrapositive are logically equivalent, we can prove the second claim instead of the first directly. Here is an argument.
Proof of claim. We argue by appealing to the contrapositive. Suppose
Intuitively, the contrapositive of the claim is easier to reason about because the hypothesis “