Uploaded by Hằng Phạm

Ass1 Q2

advertisement
Claim #1: Suppose that C has width > 0, height >0 and i, j are nonnegative integers, the algorithm netBen
is executed given C, i, j as inputs.
Then this execution of the algorithm eventually ends and the (i+j)th netBen(i,j) is returned as output
when this happens.
Proof. This will be proved by induction on point (i,j). The case that (i,j) = (0,0) will be considered in the
basis.
Basis: Suppose that (i,j) = (0,0).
Then, during the execution of the algorithm netBen on input i,j, the test at line 1 succeeds, so
execution continues with line 2. This causes the execution to terminate, with the net benefit to travel
from (0,0) to itself - netBen(0,0) = 0 being returned as output — as required for this case.
Inductive Step: Let (i,j) be a point in C and i, j are integer that:
-
Case 1: i = 0 and j ≥ 1
Case 2: i ≥ 1 and j = 0
Case 3: i ≥ 1 and j ≥ 1
Inductive: Let m and n integers such that m ≥ 1 and n ≥ 1.
Inductive Hypothesis: Suppose that i and j are a nonnegative integer such that 0 ≤ i ≤ m, 0 ≤ j ≤ n, and
(i,j) is a point in C. If the algorithm netBen is executed given C, i and j as inputs then this execution of the
algorithm eventually terminates, with the (i+j)th netBen(i,j) is returned as output.
Inductive Claim: If the algorithm fib is executed given i = k + 1 and j = q + 1 as inputs then this execution
of the algorithm eventually terminates, with the (k + q + 2)th netBen(k+1,q+1) = netBen(i,j) returned as
output.
With that noted, suppose that the algorithm netBen is executed given C, i = k + 1 and j = q + 1 as inputs.
Since k is an integer such that k ≥ 1, n is an integer such that n ≥ 2.
• Since n ≥ 2, the text at line 1 fails, so that the execution of the algorithm continues with
the execution of the test at line 3.
• Since n ≥ 2, the execution of the test at line 3 also fails, so that the execution of the
algorithm continues at line 5.
• Line 5 includes a recursive execution of this algorithm with input n−2. Since n = k +1 ≥
2, 0 ≤ n − 2 = k − 1 ≤ k, and it follows by the inductive hypothesis that this recursive
execution of the algorithm eventually ends, with Fn−2 = Fk−1 returned as output.
• Line 5 also includes a recursive execution of this algorithm with input n − 1. Since
n = k + 1 ≥ 2, 0 ≤ n − 1 = k, and it follows again by the inductive hypothesis that this
recursive execution of the algorithm eventually ends, with Fn−1 = Fk returned as output.
2
• One can now see, by inspection of line 5, that this execution of the algorithm eventually
ends. Furthermore, since k + 1 ≥ 2, it follows by the definition of Fk+1, that the value
returned as output is
Fn−2 + Fn−1 = Fk−1 + Fk = Fk+1,
as required to establish the inductive claim.
The result now follows by induction on n.
Download