Correctness for Recurrence - Induction
- Setup Predicate
Merge Sort: $P(n):l \in List[\N]$ be a list of length $n$,
merge_sort(l)
returns sorted $l$
Claim: $\forall n\in\N, P(n)$
Binary Search: Induction on the length of the search interval $b-a=n$
- Proof base cases
Merge Sort: Prove lists of length 0 and 1
- Setup inductive hypothesis
Merge Sort: Let $k\in\N,k\ge1,$ assume $\forall i \in \N, 0 \le i \le k, P(i)$
Want to show $P(k + 1)$
- Show that the parameters passed to recursive calls are in the inductive hypothesis
Merge Sort:
l[:(k + 1)//2]
have length at least $k$