Lecture07-recurrencerels

# 2 1 1 n i n n n 2 1 2 1 2 n n n n c worst 2 1 2 1 2 2

• Notes
• 44

This preview shows page 5 - 16 out of 44 pages.

)( 2 ( 1 ) 1 ( n i n n n 2 ) 1 )( 2 ( ) 1 ( ) ( 2 - - - - = n n n n C worst ) ( 2 1 2 ) 1 ( 2 2 n n n n Θ - =

Subscribe to view the full document.

Recurrence Relations
Recursive Algorithms Example : Compute Factorial function N ! function Factorial( N) if N=0 return 1 else return Factorial (N-1)*N Define input size Define elementary operations Focus on worst-case What sequence is generated by this recurrence relation? In order to answer that question we need an initial condition! Now we can build a table of values: How long to compute C(1,000,000)? Want: C(N) in closed form for quick computation. N C(N) ( ) ( 1) 4 worst worst C N C N = - + (0) 1 C =

Subscribe to view the full document.

Recursive Algorithms Example : Compute Factorial function N ! function Factorial( N) if N=0 return 1 else return Factorial (N-1)*N Define input size Define elementary operation Distinguish worst-case What sequence is generated by this recurrence relation? In order to answer that question we need an initial condition! Then we could build a table of values: How long to compute C(1,000,000)? Want: C(N) in closed form for quick computation. ( ) ( 1) 4 worst worst C N C N = - + (0) 1 C =
Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.

Subscribe to view the full document.

Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.
Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. ( ) ( 1) ... C n C n = - +

Subscribe to view the full document.

Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. ( ) ( 1) 1 ... C n C n = - + +
Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. ( ) ( 1) 1 ( 1) C n C n C n = - + + - 1 ) 1 ( 2 ) ( + - = n C n C 1 ) 1 ( = C

Subscribe to view the full document.

Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. Can you figure out an explicit (closed form) formula for this sequence? As before, build a table, recognize the pattern OR Use substitution, recognize the pattern OR Appeal to theory of recurrence relations n C(n) 1 ) 1 ( 2 ) ( + - = n C n C 1 ) 1 ( = C
Substitution 1 2 3 4 5 6 7 8 9 k y(k) ( ) 2 ( 1) 1, 2, y k y k k = - = K 2 3 (0) : initial condition (1) (0) (2) (1) (0) (3) (2) (0) y y ay y ay a y y ay a y = = = = = M

Subscribe to view the full document.

You've reached the end of this preview.
• Spring '08
• Jones,M

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern