Loop Invariants: Part 1
7 January 2019 OSU CSE 1
Loop Invariants: Part 1 7 January 2019 OSU CSE 1 Reasoning About - - PowerPoint PPT Presentation
Loop Invariants: Part 1 7 January 2019 OSU CSE 1 Reasoning About Method Calls What a method call does is described by its contract Precondition: a property that is true before the call is made Postcondition: a property that is true
7 January 2019 OSU CSE 1
7 January 2019 OSU CSE 2
7 January 2019 OSU CSE 3
7 January 2019 OSU CSE 4
7 January 2019 OSU CSE 5
7 January 2019 OSU CSE 6
7 January 2019 OSU CSE 7
7 January 2019 OSU CSE 8
7 January 2019 OSU CSE 9
7 January 2019 OSU CSE 10
7 January 2019 OSU CSE 11
7 January 2019 OSU CSE 12
7 January 2019 OSU CSE 13
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { T x = q.dequeue(); this.enqueue(x); }
7 January 2019 OSU CSE 14
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { T x = q.dequeue(); this.enqueue(x); }
7 January 2019 OSU CSE 15
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3 > q = < 4, 5, 6 > T x = q.dequeue(); this = < 1, 2, 3 > q = < 5, 6 > x = 4 this.enqueue(x); this = < 1, 2, 3, 4 > q = < 5, 6 > x = 4 }
7 January 2019 OSU CSE 16
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3 > q = < 4, 5, 6 > T x = q.dequeue(); this = < 1, 2, 3 > q = < 5, 6 > x = 4 this.enqueue(x); this = < 1, 2, 3, 4 > q = < 5, 6 > x = 4 }
7 January 2019 OSU CSE 17
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3 > q = < 4, 5, 6 > T x = q.dequeue(); this = < 1, 2, 3 > q = < 5, 6 > x = 4 this.enqueue(x); this = < 1, 2, 3, 4 > q = < 5, 6 > x = 4 }
7 January 2019 OSU CSE 18
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3, 4 > q = < 5, 6 > T x = q.dequeue(); this = < 1, 2, 3, 4 > q = < 6 > x = 5 this.enqueue(x); this = < 1, 2, 3, 4, 5 > q = < 6 > x = 5 }
7 January 2019 OSU CSE 19
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3, 4 > q = < 5, 6 > T x = q.dequeue(); this = < 1, 2, 3, 4 > q = < 6 > x = 5 this.enqueue(x); this = < 1, 2, 3, 4, 5 > q = < 6 > x = 5 }
7 January 2019 OSU CSE 20
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3, 4, 5 > q = < 6 > T x = q.dequeue(); this = < 1, 2, 3, 4, 5 > q = < > x = 6 this.enqueue(x); this = < 1, 2, 3, 4, 5, 6 > q = < > x = 6 }
7 January 2019 OSU CSE 21
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3, 4, 5 > q = < 6 > T x = q.dequeue(); this = < 1, 2, 3, 4, 5 > q = < > x = 6 this.enqueue(x); this = < 1, 2, 3, 4, 5, 6 > q = < > x = 6 }
7 January 2019 OSU CSE 22
this = < 1, 2, 3 > q = < 4, 5, 6 > while (q.length() > 0) { this = < 1, 2, 3, 4, 5 > q = < 6 > T x = q.dequeue(); this = < 1, 2, 3, 4, 5 > q = < > x = 6 this.enqueue(x); this = < 1, 2, 3, 4, 5, 6 > q = < > x = 6 }
7 January 2019 OSU CSE 23
7 January 2019 OSU CSE 24
7 January 2019 OSU CSE 25
7 January 2019 OSU CSE 26
7 January 2019 OSU CSE 27
7 January 2019 OSU CSE 28
7 January 2019 OSU CSE 29
7 January 2019 OSU CSE 30
7 January 2019 OSU CSE 31
7 January 2019 OSU CSE 32
7 January 2019 OSU CSE 33
7 January 2019 OSU CSE 34
this = < 1, 2, 3 > q = < 4, 5, 6 > /** * @maintains * this * q = #this * #q */ while (q.length() > 0) { ... } this = q =
7 January 2019 OSU CSE 35
this = < 1, 2, 3 > q = < 4, 5, 6 > /** * @maintains * this * q = #this * #q */ while (q.length() > 0) { ... } this = q =
7 January 2019 OSU CSE 36
this = < 1, 2, 3 > q = < 4, 5, 6 > /** * @maintains * this * q = #this * #q */ while (q.length() > 0) { ... } this = q =
7 January 2019 OSU CSE 37
this = < 1, 2, 3 > q = < 4, 5, 6 > /** * @maintains * this * q = #this * #q */ while (q.length() > 0) { ... } this = < 1, 2, 3, 4, 5, 6 > q = < >
7 January 2019 OSU CSE 38
7 January 2019 OSU CSE 39
7 January 2019 OSU CSE 40
7 January 2019 OSU CSE 41
7 January 2019 OSU CSE 42
/** * @updates this, q * @maintains * this * q = #this * #q * @decreases * |q| */ while (q.length() > 0) { T x = q.dequeue(); this.enqueue(x); }
7 January 2019 OSU CSE 43
/** * @updates this, q * @maintains * this * q = #this * #q * @decreases * |q| */ while (q.length() > 0) { T x = q.dequeue(); this.enqueue(x); }
7 January 2019 OSU CSE 44
7 January 2019 OSU CSE 45