Internet Engineering Czesław Smutnicki Discrete Mathematics – Recursive Equations
CONTENT S Recursive equations Generating functions
HANOI TOWERS ABC
HANOI TOWERS cont. lr(n) – the number of moves (for n discs). n=0, lr(0)=0 n=1 ALG(1) K1: move disc on C.lr(1)=1 n=2 ALG(2) K1: small on B; K2: large on C K3: small on C;lr(2)=3 n=3 ALG(3) K1: small on C; K2: medium on B K3: small on B K4: large on C K5: small on A K6: medium on C K7: small on C lr(3)=7 n=4 ALG(4) KROK 1: 3 upper discs from A on B (alg. ALG(3))lr(3) KROK 2: large na C1 move KROK 3: 3 upper discs from B on C (alg. ALG(3))lr(3) lr(4)=2lr(3)+1
HANOI TOWERS cont. n lr(n) Generally lr(n)=2lr(n-1)+1=2n-1 with initial condition lr(0)=0.
FIBONACCI NUMBERS Fibonacci numbers a)Recursive formula F 1 = 1;F 2 = 1; F n = F n-1 + F n-2, dla n > 2 b) Analytically
RABBITS M M M M M M M R RARA RARA RARA RARA RARA RARA RARA RARA RARA RARA M RARA pary okresy
CIRCLES 1 = = 2 = = 4 = Similarly for n=3 we have: = 8 = 2 3 for n=4 we have: = 16 = 2 4
SOLUTION METHOD. CASE STUDY I Given recursive sequence: (1) a n = 2 a n-1 + 1, n > 1 with initial value a 1 =1 The sequence starts from: 1, 3, 7, 15, 31, Find algebraic formula for the n-th element of the sequence. For n-1 we have: a n-1 =2 a n-2 + 1, which we substitute into equation (1). Such substitution we continue until we obtain a 1, so a n = 2·a n = 2·(2·a n-2 + 1) + 1 = 2 2 ·a n = = 2 2 ·(2·a n-3 + 1) = 2 3 ·a n =... = 2 k a n-k + 2 k k = = 2 n n = 2 n – 1
SOLUTION METHOD. CASE STUDY I. cont This is the sum of a geometric sequence with the ratio q=a i+1 /a i =2 and a 1 =1; so S= (1-2 n )/(1-2) = - (1-2 n ) = 2 n –1. Therefore a n =2 n –1. We can check this below. n a n =2a n-1 + 1a n = 2 n *1 + 1 = 3 2*3 + 3 = 7 2*7 + 1 = 15 2* = – 1=3 2 3 –1 =7 2 4 – 1= – 1=31
SOLUTION METHOD. CASE STUDY II. Consider the equation: s n = as n-1 + bs n-2 where values s 0 and s 1 are known, and a,b - are certain constants Case a) either a = 0 or b = 0 If b=0 then s n = as n-1 for n 1. Therefore s 1 = as 0, s 2 = as 1 = a 2 s 0,... and finally s n = a n s 0. If a = 0 then s n = bs n-2 for n 2. Therefore s 2 =bs 0, s 4 =bs 2 =b 2 s 0 and finally … s 2n =b n s 0 n N Similarly s 3 = bs 1, s 5 = bs 3 = b 2 s 1 and finally s 2n+1 = b n s 1 n N
SOLUTION METHOD. CASE STUDY II. cont Case b) a ≠ 0 or b ≠ 0 has characteristics equation x 2 - ax - b = 0 This equation follows from the suppositionfor the given constant c. Hence dividing by C we obtain then r is the root of the equation x 2 - ax - b = 0
Thank you for your attention DISCRETE MATHEMATICS Czesław Smutnicki