0% found this document useful (0 votes)
9 views

Chapter 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chapter 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 4: Induction and Recursion

4.2 Strong Induction


1.
a. P(8) is true: 8 cents = 3 + 5
P(9) is true: 9 cents = 3 * 3
P(10) is true: 10 cents = 2 * 5
b. P(j): “ j cents can be formed using just 3-cent stamps and 5-cent
stamps” is true for 8 ≤ j ≤ k, k ≥ 10
c. P(k+1): “k + 1 cents can be formed using just 3-cent stamps and 5-
cent stamps” is true for k ≥ 10
d. We can form k + 1 cents by adding 3-cent stamps to k – 2 cents
Using inductive hypothesis, we have P(k – 2) is true because 8 ≤ k – 2
<k
→ P(k + 1) is true. → Proved

2.
a. P(18) is true: 18 cents = 4 + 2.7.
P(19) is true: 19 cents = 3.4 + 7.
P(20) is true: 20 cents = 5.4.
P(21) is true: 21 cents = 3.7.
b. P(j): “j cents can be formed using just 4-cent stamps and 7-cent
stamps” is true for 18 ≤ j ≤ k, k ≥ 21.
c. P(k + 1): “k + 1 cents can be formed using just 4-cent stamps and 7-
cent stamps” is true for k ≥ 21.
d. We can form k + 1 cents by adding 4-cent stamps to k – 3 cents.
Using inductive hypothesis, we have P(k – 3) is true because 18 ≤ k –
3 < k.
→ P(k + 1) is true. → Proved.
4.3 Recursive Definitions and Structural Induction

1.
a. f(n + 1) = f(n) + 2
f(1) = f(0) + 2 = 1 + 2 = 3.
f(2) = f(1) + 2 = 3 + 2 = 5.
f(3) = f(2) + 2 = 5 + 2 = 7.
f(4) = f(3) + 2 = 7 + 2 = 9.
b. f(n + 1) = 3f(n)
f(1) = 3f(0) = 3.1 = 3
f(2) = 3f(1) = 3.3 = 9
f(3) = 3f(2) = 3.9 = 27
f(4) = 3f(3) = 3.27 = 81
c. f(n + 1) = 2f(n)
f(1) = 2f(0) = 2.1 = 2
f(2) = 2f(1) = 2.2 = 4
f(3) = 2f(2) = 2.4 = 8
f(4) = 2f(3) = 2.8 = 16
d. f(n + 1) = f(n)2 + f(n) + 1
f(1) = f(0)2 + f(0) + 1 = 12 + 1 + 1 = 3
f(2) = f(1)2 + f(1) + 1 = 32 + 3 + 1 = 13
f(3) = f(2)2 + f(2) + 1 = 132 + 13 + 1 =183
f(4) = f(3)2 + f(3) + 1 = 1832 + 183 + 1 = 33673

2.
a. f(n + 1) = f(n) + 3f(n − 1)
f(2) = f(1) + 3f(0) = 2 + 3(–1) = –1
f(3) = f(2) + 3f(1) = –1 + 3.2 = 5
f(4) = f(3) + 3f(2) = 5 + 3(–1) = 2
f(5) = f(4) + 3f(3) = 2 + 3.5 = 17
b. f(n + 1) = f(n)2 * f (n − 1)
f(2) = f(1)2 * f(0) = 22.( –1) = –4
f(3) = f(2)2 * f(1) = (–4)2.2 = 32
f(4) = f(3)2 * f(2) = 322.( –4) = –4096
f(5) = f(4)2 * f(3) = (–4096)2.32 = 536870912
c. f (n + 1) = 3f (n)2 − 4f (n − 1)2
f(2) = 3f(1)2 – 4f(0)2 = 3.22 – 4.( –1)2 = 8
f(3) = 3f(2)2 – 4f(1)2 = 3.82 – 4.22 = 176
f(4) = 3f(3)2 – 4f(2)2 = 3.1762 – 4.82 = 92672
f(5) = 3f(4)2 – 4f(3)2 = 3.926722 – 4.1762 = 25764174848
d. f(n + 1) = f(n − 1)/f (n)
f(2) = f(0)/f(1) = (–1)/2 = –1/2
f(3) = f(1)/f(2) = 2/(–1/2) = –4
f(4) = f(2)/f(3) = (–1/2)/( –4) = 1/8
f(5) = f(3)/f(4) = (–4)/(1/8) = –32

3.
a. f(n + 1) = f(n) − f(n − 1)
f(2) = f(1) – f(0) = 1 – 1 = 0
f(3) = f(2) – f(1) = 0 – 1 = –1
f(4) = f(3) – f(2) = –1 – 0 = –1
f(5) = f(4) – f(3) = –1 – (–1) = 0
b. f(n + 1) = f(n) * f (n − 1)
f(2) = f(1).f(0) = 1.1 = 1
f(3) = f(2).f(1) = 1.1 = 1
f(4) = f(3).f(2) = 1.1 = 1
f(5) = f(4).f(3) = 1.1 = 1
c. f(n + 1) = f(n)2 + f(n − 1)3
f(2) = f(1)2 + f(0)3 = 1 + 1 = 2
f(3) = f(2)2 + f(1)3 = 22 + 12 = 5
f(4) = f(3)2 + f(2)3 = 52 + 22 = 29
f(5) = f(4)2 + f(3)3 = 292 + 52 = 866
d. f(n + 1) = f(n)/f(n − 1)
f(2) = f(1)/f(0) = 1/1 = 1
f(3) = f(2)/f(1) = 1/1 = 1
f(4) = f(3)/f(2) = 1/1 = 1
f(5) = f(4)/f(3) = 1/1 = 1

4.

5.
a. an = 6n
a1 = 6
an+1 = an + 6
b. an = 2n + 1
a1 = 3
an+1 = an + 2
c. an = 10n
a1 = 10
an+1 = an + 10

d. an = 5
a1 = 5
an+1 = an
e. an = 4n – 2
a1 = 2
an+1 = an + 4
f. an = 1 + (−1)n
a1 = 0
an+1 = 2 – an
g. an = n(n + 1)
a1 = 2
an+1 = an + 2(n + 1)
h. an = n2
a1 = 1
an+1 = an + 2n + 1

6.
F(1) = 1
F(n+1) = F(n) + n + 1

7.
a. A = {2, 5, 8, 11, 14, …}
Basic step: 2 ∈ A.
Recursive step: If x ∈ A, then x + 3 ∈ A.
b. B = {…, -5, -1, 3, 7, 10, …}
Basic step: –5 ∈ B.
Recursive step: If x ∈ B, then x ± 4 ∈ B.
c. C = {3, 12, 48, 192, 768, …}
Basic step: 3 ∈ C.
Recursive step: If x ∈ C, then 4x ∈ C.
d. D = {1, 2, 4, 7, 11, 16, …}
Basic step: 1 ∈ D.
Recursive step: If x ∈ D, then (x + 1/2 + √ 2 x −7/4 ) ∈ D.

8.
a. 0101 1010
b. 1 1011 1 1011
c. 1000 1001 0111 1110 1001 0001

9.
When that string has the form “00...0011...11” with n number 0 and n
number 1, n is a positive integer.

4.4 Recursive Algorithms


1. Give a recursive algorithm for computing nx whenever n is a positive integer
and x is an integer, using just addition.
procedure multiply(x: integer, n: positive integer)
if n = 1 then return x
else return x + multiply(x, n – 1)

2. Consider an recursive algorithm to compute the nth Fibonacci number:


procedure Fibo(n : positive integer)
if n = 1 return 1
else if n = 2 return 1
else return Fibo(n – 1) + Fibo(n – 2)
How many additions (+) are used to find Fibo(6) by the algorithm above?
There are 7 additions.

3. Give a recursive algorithm for finding the sum of the first n odd positive
integers.
procedure sumOdd(n: positive integer)
if n = 1 then return 1
else return 2n – 1 + sumOdd(n – 1)

4. Consider the following algorithm:


procedure tinh(a: real number; n: positive integer)
if n = 1 return a
else return a∙tinh(a, n-1).
a. What is the output if inputs are: n = 4, a = 2.5? Explain your answer.
tinh(2.5, 4)
= 2.5∙tinh(2.5, 3)
= 2.5∙2.5∙tinh(2.5, 2)
= 2.5∙2.5∙2.5∙tinh(2.5, 1)
= 2.5∙2.5∙2.5∙2.5 = 39.0625
b. Show that the algorithm computes an using Mathematical Induction.
Let P(n): “tinh(a,n) = an”.
Basic step: P(1) is true, because tinh(a, 1) = a = a1.
Inductive step: Assume that P(k): “tinh(a,k) = ak” is true for k > 0.
Prove that P(k + 1): “tinh(a, k+1) = ak+1” is true.
We have
tinh(a, k+1) = a∙tinh(a,k) = a. ak = ak+1.
→ P(k + 1) is true → Proved.

5. Consider the following algorithm:


procedure F(a1, a2, a3, ...,an: integers)
if n = 0 return 0
else return an + F(a1, a2, a3, ...,an-1)
Find
a. F(1,3,5)
= 5 + F(1,3)
= 5 + 3 + F(1)
= 5 + 3 + 1 + F()
=5+3+1+0=9
b. F(1,2,3,5,9)
= 9 + F(1,2,3,5)
= 9 + 5 + F(1,2,3)
= 9 + 5 + 3 + F(1,2)
= 9 + 5 + 3 + 2 + F(1)
= 9 + 5 + 3 + 2 + 1 + F()
= 9 + 5 + 3 + 2 + 1 + 0 = 20

You might also like