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

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 Θ - =
Image of page 5

Subscribe to view the full document.

Recurrence Relations
Image of page 6
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 =
Image of page 7

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 =
Image of page 8
Recursive Algorithms Example : Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.
Image of page 9

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.
Image of page 10
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 = - +
Image of page 11

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 = - + +
Image of page 12
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
Image of page 13

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
Image of page 14
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
Image of page 15

Subscribe to view the full document.

Image of page 16
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern