COMP232 - Mathematics for Computer Science Tutorial 10 Ali Moallemi moa [email protected] Iraj Hedayati h [email protected] Concordia University, Fall 2015 Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 1 / 16 Table of Contents 1 5.3 Recursive Definitions and Structural Induction Exercise 3 Exercise 6 Exercise 8 Exercise 13 Exercise 20 Exercise 21 Exercise 28 Exercise 42 Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 2 / 16 Exercise 3 Find f (2), f (3), f (4), and f (5) if f is defined recursively by f (0) = −1, f (1) = 2, and for n = 1, 2, . . . a) f (n + 1) = f (n) + 3f (n − 1). Answer: f (2) = f (1) + 3f (0) = 2 + 3 · (−1) = −1 f (3) = f (2) + 3f (1) = −1 + 6 = 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). Answer: 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 = 536, 870, 912 Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 3 / 16 Exercise 3 - Cont... Find f (2), f (3), f (4), and f (5) if f is defined recursively by f (0) = −1, f (1) = 2, and for n = 1, 2, . . . c) f (n + 1) = 3f (n)2 − 4f (n − 1)2 . Answer: f (2) = 3 · f (1)2 − 4f (0)2 = 3 · 22 − 4(−1)2 = 8 f (3) = 3 · f (2)2 − 4f (1)2 = 3 · 82 − 4(2)2 = 176 f (4) = 3 · f (3)2 − 4f (2)2 = 3 · 1762 − 4(8)2 = 92, 672 f (5) = 3 · f (4)2 − 4f (3)2 = 3 · 92.6272 − 4(176)2 2 = 25, 764, 174, 848 d) f (n + 1) = f (n − 1)/f (n). Answer: f (2) = f (0)/f (1) = −1/2 f (3) = f (1)/f (2) = −21 = −4 2 f (4) = f (2)/f (3) = f (5) = f (3)/f (4) = Ali Moallemi, Iraj Hedayati − 12 −4 −4 1 8 = 18 = −32 COMP232 - Mathematics for Computer Science 4 / 16 Exercise 6 Determine whether each of these proposed definitions is a valid recursive definition of a function f from the set of nonnegative integers to the set of integers. If f is well defined, find a formula for f (n) when n is a nonnegative integer and prove that your formula is valid. a) f (0) = 1, f (n) = −f (n − 1) for n ≥ 1 Answer: Is Valid f (n) = (−1)n proof. Basis step: f (0) = (−1)0 = 1 Inductive: if f (k) = (−1)k then,f (k + 1) = (−1)k+1 = (−1) · (−1)k Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 5 / 16 Exercise 6 - Cont... Determine whether each of these proposed definitions is a valid recursive definition of a function f from the set of nonnegative integers to the set of integers. If f is well defined, find a formula for f (n) when n is a nonnegative integer and prove that your formula is valid. b) f (0) = 1, f (1) = 0, f (2) = 2, f (n) = 2f (n − 3) for n ≥ 3 Answer: Is Valid 0 if n mod 3 = 1 f (n) = dn/3e 2 otherwise proof. Basis step: f (0) = 2d0/3e = 20 = 1, f (1) = 0, f (2) = 2d2/3e = 21 = 2 Inductive: if f (k) = 2dk/3e then, f (k − 2) = 2d(k−2)/3e and f (k + 1) = 2d(k+1)/3e = 2 · 2d(k−2)/3e Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 6 / 16 Exercise 6 - Cont... Determine whether each of these proposed definitions is a valid recursive definition of a function f from the set of nonnegative integers to the set of integers. If f is well defined, find a formula for f (n) when n is a nonnegative integer and prove that your formula is valid. c) f (0) = 0, f (1) = 1, f (n) = 2f (n + 1) for n ≥ 2 Answer: Is not Valid Because value of f (n) depends on n + 1 d) f (0) = 0, f (1) = 1, f (n) = 2f (n − 1) for n ≥ 1 Answer: Is not Valid Because f (1) = 1 in basis step and is f (1) = 2f (0) = 0 in inductive step. Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 7 / 16 Exercise 6 - Cont... Determine whether each of these proposed definitions is a valid recursive definition of a function f from the set of nonnegative integers to the set of integers. If f is well defined, find a formula for f (n) when n is a nonnegative integer and prove that your formula is valid. e) f (0) = 2, f (n) = f (n − 1) if n is odd and n ≥ 1 and f (n) = 2f (n − 2) if n ≥ 2 Answer: Is Valid f (n) = 2d(n+1)/2e proof. Basis step: f (0) = 21 = 2 Inductive: if f (k) = 2d(k+1)/2e then,f (k + 1) = 2d(k+2)/2e I I If k + 1 is odd, f (k + 1) = 2d(k+2)/2e = 2d(k+1)/2e = f (k) If k + 1 ≥ 2, f (k + 1) = 2d(k+2)/2e = 2 · 2dk/2e = 2f (k − 1) Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 8 / 16 Exercise 8 Give a recursive definition of the sequence {an }, n = 1, 2, 3, · · · if a) an = 4n − 2. Answer: f (1) = 2, f (n) = f (n − 1) + 4 b) an = 1 + (−1)n . Answer: f (1) = 0, f (n) = 2 − f (n − 1) c) an = n(n + 1). Answer: f (1) = 2, f (n) = 2n + f (n − 1) d) an = n2 . Answer: f (1) = 1, f (n) = 2n − 1 + f (n − 1) Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 9 / 16 Exercise 13 Prove that f1 + f3 + . . . + f2n−1 = f2n when n is a positive integer. Answer: (fn is nth Fibonancci number) Let P(n) be f1 + f3 + . . . + f2n−1 = f2n Basis step: P(1) is true because f1 = 1 = f2 . Inductive step: Assume that P(k) is true. Then f1 + f3 + . . . + f2k−1 + f2k+1 = f2k + f2k+1 = f2k+2 = f2(k+1) Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 10 / 16 Exercise 20 Give a recursive definition of the functions max and min so that max(a1 , a2 , ..., an ) and min(a1 , a2 , ..., an ) are the maximum and minimum of the n numbers a1 , a2 , ..., an , respectively. answer: max(a) = a max(a1 , a2 , ..., an ) = max(max(a1 , a2 , ..., an−1 ), an ) min(a) = a min(a1 , a2 , ..., an ) = min(min(a1 , a2 , ..., an−1 ), an ) Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 11 / 16 Exercise 21 Let a1 , a2 , ..., an , and b1 , b2 , ..., bn be real numbers. Use the recursive definitions that you gave in Exercise 20 to prove these. a) max(−a1 , −a2 , ..., −an ) = min(a1 , a2 , ..., an ) answer: Proof by induction. Basis step: For n = 1, max(−a1 ) = −a1 = −min(a1 ). For n = 2, there are two cases. If a2 ≥ a1 , then −a1 ≥ −a2 , so max(−a1 , −a2 ) = −a1 = −min(a1 , a2 ). If a2 < a1 , then −a1 < −a2 , so max(−a1 , −a2 ) = −a2 = −min(a1 , a2 ). Inductive step: Assume it is true for k with k ≥ 2. Then max(−a1 , −a2 , ..., −ak , −ak+1 ) = max(max(−a1 , ..., −ak ), −ak+1 ) = max(−min(a1 , ..., ak ), −ak+1 ) = −min(min(a1 , ..., ak ), ak+1 ) = −min(a1 , ..., ak+1 ). Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 12 / 16 Exercise 21 Cont... b) max(a1 + b1 , a2 + b2 , ..., an + bn ) ≤ max(a1 , a2 , ..., an ) + max(b1 , b2 , ..., bn ) answer: Proof by mathematical induction. Basis step: For n = 1, the result is the identity a1 + b1 = a1 + b1 . For n = 2, first consider the case in which a1 + b1 ≥ a2 + b2 . Then max(a1 + b1 , a2 + b2 ) = a1 + b1 . Also note that a1 ≤ max(a1 , a2 ) and b1 ≤ max(b1 , b2 ), so a1 + b1 ≤ max(a1 , a2 ) + max(b1 , b2 ). Therefore, max(a1 + b1 , a2 + b2 ) = a1 + b1 ≤ max(a1 , a2 ) + max(b1 , b2 ).The case with a1 + b1 < a2 + b2 is similar. Inductive step: Assume that the result is true for k. Then max(a1 + b1 , a2 + b2 , ..., ak + bk , ak+1 + bk+1 ) = max(max(a1 + b1 , a2 + b2 , ..., ak + bk ), ak+1 + bk+1 ) ≤ max(max(a1 , a2 , ..., ak ) + max(b1 , b2 , ..., bk ), ak+1 + bk+1 ) ≤ max(max(a1 , a2 , ..., ak ), ak+1 ) + max(max(b1 , b2 , ..., bk ), bk+1 ) = max(a1 , a2 , ..., ak , ak+1 ) + max(b1 , b2 , ..., bk , bk+1 ). Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 13 / 16 Exercise 21 Cont... c) min(a1 + b1 , a2 + b2 , ..., an + bn ) ≥ min(a1 , a2 , ..., an ) + min(b1 , b2 , ..., bn ) answer: Proof by mathematical induction. Basis step: For n = 1, the result is the identity a1 + b1 = a1 + b1 . For n = 2, first consider the case in which a1 + b1 ≥ a2 + b2 . Then min(a1 + b1 , a2 + b2 ) = a1 + b1 . Also note that a1 ≥ min(a1 , a2 ) and b1 ≥ min(b1 , b2 ), so a1 + b1 ≥ min(a1 , a2 ) + min(b1 , b2 ). Therefore, min(a1 + b1 , a2 + b2 ) = a1 + b1 ≥ min(a1 , a2 ) + min(b1 , b2 ).The case with a1 + b1 > a2 + b2 is similar. Inductive step: Assume that the result is true for k. Then min(a1 + b1 , a2 + b2 , ..., ak + bk , ak+1 + bk+1 ) = min(min(a1 + b1 , a2 + b2 , ..., ak + bk ), ak+1 + bk+1 ) ≥ min(min(a1 , a2 , ..., ak ) + min(b1 , b2 , ..., bk ), ak+1 + bk+1 ) ≥ min(min(a1 , a2 , ..., ak ), ak+1 ) + min(min(b1 , b2 , ..., bk ), bk+1 ) = min(a1 , a2 , ..., ak , ak+1 ) + min(b1 , b2 , ..., bk , bk+1 ). Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 14 / 16 Exercise 28 Give a recursive definition of each of these sets of ordered pairs of positive integers. [Hint: Plot the points in the set in the plane and look for lines containing points in the set.] a) S = {(a, b)|a ∈ Z+ , b ∈ Z+ , and a + b is odd } answer: (1, 2) ∈ S, (2, 1) ∈ S If (a, b) ∈ S then (a + 2, b), (a, b + 2) and (a + 1, b + 1) ∈ S. b) S = {(a, b)|a ∈ Z+ , b ∈ Z+ , and a|b} answer: (a, a) ∈ S for all a ∈ Z+ If (a, b) ∈ S then (a, b + a) ∈ S. c) S = {(a, b)|a ∈ Z+ , b ∈ Z+ , and 3|a + b} answer: (1, 2) ∈ S, (2, 1) ∈ S If (a, b) ∈ S then (a + 3, b), (a, b + 3), (a + 2, b + 1) and (a + 1, b + 2) ∈ S. Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 15 / 16 Exercise 42 Show that (w R )i = (w i )R whenever w is a string and i is a nonnegative integer; that is, show that the ith power of the reversal of a string is the reversal of the ith power of the string. answer: Proof by mathematical induction. Basis step: For i = 1, the result is the identity (w R )1 = w R = (w 1 )R .For Inductive step: Assume that the result is true for k. Then (w R )k+1 = (w R )k w R = (w k )R w R = (w · w k )R = (w k+1 )R . Ali Moallemi, Iraj Hedayati COMP232 - Mathematics for Computer Science 16 / 16
© Copyright 2026 Paperzz