CMPSCI 311: Theory of Algorithms

from Wednesday 17 Sept 2003

Questions are in black, answers in blue.

• Question 1: A(n) = A(n-1) + 3n2 -3n +1; A(0) = 0

Trying cases: A(1) = 0+3*1-3*1+1 = 1; A(2) = 1+3*4-3*2+1 = 8, A(3) = 8+3*9-3*3+1 = 27, A(4) = 27+3*16-3*4+1 = 64, looks like A(n)=n3.

Base Case: From the definition A(0) = 0 = 03.

Inductive Hypothesis: A(n-1) = (n-1)3

Inductive Goal: A(n) = n3

Proof: A(n) = A(n-1) + 3n2 - 3n + 1 by definition, which is (n-1)3+3n2-3n+1 by the IH. By arithmetic, this is n3 as desired.

• Question 2: B(n) = 2B(n-1) - B(n-2); B(0) = 0, B(1) = 1

Trying cases: B(2) = 2*1 - 0 = 2; B(3) = 2*2-1 = 3, B(4) = 2*3-2 = 4, looks like B(n)=n.

Base Case: From the definition B(0)=0 and B(1)=1, so B(n)=n holds there.

Inductive Hypothesis: B(n-1)=n-1 and B(n-2)=n-2 (part of the strong inductive hypothesis that B(i)=i for all i with i<n)

Inductive Goal: B(n) = n

Proof: By definition B(n) = 2B(n-1) - B(n-2, by the IH B(n) = 2(n-1)-(n-2), by arithmetic this is n as desired.

• Question 3: C(n) = 3C(n-1) - 2C(n-2); C(0)=0, C(1)=1

Cases: C(2) = 3*1-2*0 = 3; C(3) = 3*3-2*1 = 7; C(4) = 3*7-2*3 = 15, C(5) = 3*15-2*7 = 31, C(6) = 3*31-2*15 = 63, comparing with 2n we see that it looks like C(n) = 2n-1.

Base Case: C(0) = 20-1 = 0 and C(1) = 21-1 = 1, so the claimed formula holds for the two base cases.

Inductive Hypothesis: C(n-1) = 2n-1-1 and C(n-2) = 2n-2-1.

Inductive Goal: C(n) = 2n-1

Proof: C(n) = 3C(n-1)-2C(n-2) by the definition, which is 3*(2n-1-1) - 2*(2n-2-1) by the IH. By arithmetic this is 3*2n-1-3-2n-1+2 = 2n-1, as desired.

• Question 4: D(n) = 2D(n/2) + 3; D(1) = 1 (solve for n=2k)

Cases: D(2) = 2*1+3 = 5, D(4) = 2*5+3 = 13, D(8) = 2*13+3 = 29, D(16) = 2*29+3 = 61, D(32) = 2*61+3 = 125, checking against powers of two we guess D(2k) = 2n+2-3 or equivalently D(n) = 4n-3 when n is a power of two.

Base Case: D(1) = 1 = 4*1-3 so the formula holds in this case.

Inductive Hypothesis: D(n/2) = 4*(n/2)-3, part of the strong inductive hypothesis that the claimed formula holds true for all powers of two that are less than n.

Inductive Goal: D(n) = 4n-3

Proof: D(n) = 2D(n/2)+3 by definition, which equals 2*(4*(n/2)-3)+3 by the IH (since half of a power of two is a power of two unless the former is 1, which it isn't). By arithmetic this is 4n-6+3 = 4n-3 as desired. The arithmetic is essentially the same if you leave n in the form of 2k, though it may look different.

• Question 5: E(n) = 2E(n/2) + n; E(1) = 0 (solve for n=2k)

Cases: E(2) = 2*1+0 = 2; E(4) = 2*2+4 = 8; E(8) = 2*8+8 = 24; E(16) = 2*24+16 = 64; E(32) = 2*64+32 = 160; E(64) = 2*160+64 = 384. Checking against powers of two we see that E(2k) = (k)2k, or E(n) = n(log n).

Base Case: E(1) = 1(log 1) = 1*0 = 0 so the formula holds for n=1.

Inductive Hypothesis: E(n/2) = (n/2)(log(n/2) = (n/2)((log n)-1)

Inductive Goal: E(n) = n(log n)

Proof: E(n) = 2E(n/2) + n by the definition, which is 2((n/2)((log n)-1))+n by the IH. By arithmetic this is n((log n)-1) + n = n*log(n) as desired.

• Question 6: F(n) = 2F(n/2) + n2; F(1) = 2 (solve for n=2k)

Cases: F(2) = 2*2 + 4 = 8; F(4) = 2*8 + 16 = 32; F(8) = 2*32 + 64 = 128; note that F(2k) seems to always be a power of two, looks like F(2k) = 22k+1 or F(n) = 2n2 when n is a power of two.

Base Case: F(1) = 22*1-1 = 2, so the formula holds for n=1.

Inductive Hypothesis: F(n/2) = 2(n/2)2 = n2/2

Inductive Goal: F(n) = 2n2

Proof: F(n) = 2F(n/2) + n2 by the definition, which is 2*(n2/2) + n2 by the IH. By artihmetic this is n2 + n2 = 2n2 as desired.