Lecture 5: Loop Invariants and Insertion-sort
COMS10007 - Algorithms
- Dr. Christian Konrad
11.01.2019
- Dr. Christian Konrad
Lecture 5: Loop Invariants and Insertion-sort 1 / 12
Lecture 5: Loop Invariants and Insertion-sort COMS10007 - Algorithms - - PowerPoint PPT Presentation
Lecture 5: Loop Invariants and Insertion-sort COMS10007 - Algorithms Dr. Christian Konrad 11.01.2019 Dr. Christian Konrad Lecture 5: Loop Invariants and Insertion-sort 1 / 12 Proofs by Induction Structure of a Proof by Induction 1 Statement
Lecture 5: Loop Invariants and Insertion-sort 1 / 12
1 Statement to Prove:
2 Induction hypothesis:
3 Induction step:
4 Base case: Prove that P(1) holds
Lecture 5: Loop Invariants and Insertion-sort 2 / 12
1 Base case (n = 4): 4! = 24 ≥ 16 = 24 2 Induction hypothesis: n! ≥ 2n holds for n 3 Induction step:
1 Base case (n = 1): 31 − 1 = 2 2 Induction hypothesis: 3n − 1 is an even number 3 Induction step:
Lecture 5: Loop Invariants and Insertion-sort 3 / 12
1 Base case (n = 0): a0 = 1 2 Induction hypothesis: am = 1, for every 0 ≤ m ≤ n (strong
3 Induction step:
Lecture 5: Loop Invariants and Insertion-sort 4 / 12
Lecture 5: Loop Invariants and Insertion-sort 5 / 12
Lecture 5: Loop Invariants and Insertion-sort 6 / 12
1 Let sj be the value of s prior to iteration j 2 Initialization: s2 = 1 = (2 − 1)! 3 Maintenance: sj+1 = sj · j = (j − 1)! · j = j! 4 Termination: After iteration n, i.e., before iteration n + 1,
Lecture 5: Loop Invariants and Insertion-sort 7 / 12
Lecture 5: Loop Invariants and Insertion-sort 8 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 9 / 12
Lecture 5: Loop Invariants and Insertion-sort 10 / 12
Lecture 5: Loop Invariants and Insertion-sort 11 / 12
Lecture 5: Loop Invariants and Insertion-sort 12 / 12