Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.

Similar presentations


Presentation on theme: "Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO."— Presentation transcript:

1 Discrete Math For Computing II

2 Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO Box 830688 Richardson, TX 75083 Email: praba@utdallas.edu Phone: 972 883 4680; Fax: 972 883 2349 URL: http://www.utdallas.edu/~praba/cs3305.html Office: ES 3.706 Office Hours: 1-2pm Tuesdays, Thursdays Other times by appointments through email Announcements: Made in class and on course web page. TA: TBA.

3 Example Applications Growth of bank account Initial Amount P 0 =$10,000 After n Years= P n Compound Interest I = 11% Soln: P n =P n-1 +(I/100)P n-1 =(1.11)P n-1 Using Iteration we get, P n =(1.11) n P 0 i.e P 30 =(1.11) 30 10,000=$228,922.97

4 Example Application Rabbits and Fibonacci Numbers Growth of rabbit population in which each rabbit yields 1 new one every period starting 2 periods after its birth. P n = P n−1 + P n−2 (Fibonacci relation)

5 Classic Tower of Hanoi Example Problem: Get all disks from peg 1 to peg 2. – Only move 1 disk at a time. – Never set a larger disk on a smaller one.

6 Hanoi Recurrence Relation Let H n = # moves for a stack of n disks. Optimal strategy: – Move top n−1 disks to spare peg. (H n−1 moves) – Move bottom disk. (1 move) – Move top n−1 to bottom disk. (H n−1 moves) Note: H n = 2H n−1 + 1

7 Why is H n = 2H n-1 + 1 – Only move 1 disk at a time. – Never set a larger disk on a smaller one.

8 Solving Tower of Hanoi RR H n = 2 H n−1 + 1 = 2 (2 H n−2 + 1) + 1 = 2 2 H n−2 + 2 + 1 = 2 2 (2 H n−3 + 1) + 2 + 1= 2 3 H n−3 + 2 2 + 2 + 1 … = 2 n−1 H 1 + 2 n−2 + … + 2 + 1 = 2 n−1 + 2 n−2 + … + 2 + 1(since H 1 =1) = 2 n − 1

9 §6.2: Solving Recurrences Definition: A linear homogeneous recurrence relation of degree k with constant coefficient is a recurrence relation of the form a n = c 1 a n−1 + … + c k a n−k, where the c i are all real, and c k ≠ 0. The solution is uniquely determined if k initial conditions a 0 …a k−1 are provided

10 §6.2: Solving Recurrences.. Linear?: Right hand side is sum of multiples of previous terms. Homogenous?: No terms that are NOT multiples of the a j s. Degree?: k-degree since previous k terms are used.

11 Solving with const. Coefficients Basic idea: Look for solutions of the form a n = r n, where r is a constant. This requires the characteristic equation: r n = c 1 r n−1 + … + c k r n−k, i.e., r k − c 1 r k−1 − … − c k = 0 (Dividing both sides by r n-k and subtracting right hand side from left). The solutions (characteristic roots) can yield an explicit formula for the sequence.

12 Solving …… Theorem1: Let c 1 and c 2 be real numbers. Suppose that r 2 − c 1 r − c 2 = 0 has two distinct roots r 1 and r 2. Then the sequence {a n } is a solution of the recurrence relation a n = c 1 a n−1 + c 2 a n−2 if and only if a n = α 1 r 1 n + α 2 r 2 n for n≥0, where α 1, α 2 are constants.

13 Example Solve the recurrence a n = a n−1 + 2a n−2 given the initial conditions a 0 = 2, a 1 = 7. An = rn  rn = r n-1 + 2rn-2  r2 = r +2 Solution: Use theorem 1 – c 1 = 1, c 2 = 2 – Characteristic equation: r 2 − r − 2 = 0 – Solutions: r = [−(−1)±((−1) 2 − 4·1·(−2)) 1/2 ] / 2·1 = (1±9 1/2 )/2 = (1±3)/2, so r = 2 or r = −1. – So a n = α 1 2 n + α 2 (−1) n.

14 Example Continued… To find α 1 and α 2, solve the equations for the initial conditions a 0 and a 1 : a 0 = 2 = α 1 2 0 + α 2 (−1) 0 a 1 = 7 = α 1 2 1 + α 2 (−1) 1 Simplifying, we have the pair of equations: 2 = α 1 + α 2 7 = 2α 1 − α 2 which we can solve easily by substitution: α 2 = 2−α 1 ; 7 = 2α 1 − (2−α 1 ) = 3α 1 − 2; 9 = 3α 1 ; α 1 = 3; α 2 = -1. Final answer:a n = 3·2 n − (−1) n


Download ppt "Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO."

Similar presentations


Ads by Google