This preview shows pages 1–11. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 473: Algorithms Chandra Chekuri [email protected] 3228 Siebel Center University of Illinois, UrbanaChampaign Fall 2009 Chekuri CS473ug Fibonacci Numbers Part I Introduction to Dynamic Programming Chekuri CS473ug Fibonacci Numbers Recursion Reduction: reduce one problem to another Recursion: a special case of reduction reduce problem to a smaller instance of itself selfreduction Chekuri CS473ug Fibonacci Numbers Recursion Reduction: reduce one problem to another Recursion: a special case of reduction reduce problem to a smaller instance of itself selfreduction Problem instance of size n is reduced to one or more instances of size n 1 or less. For termination, problem instances of small size are solved by some other method as base cases Chekuri CS473ug Fibonacci Numbers Recursion in Algorithm Design Tail Recursion: problem reduced to a single recursive call after some work. Easy to convert algorithm into iterative or greedy algorithms. Examples: Interval scheduling, MST algorithms, etc. Divide and Conquer: problem reduced to multiple independent subproblems that are solved separately. Conquer step puts together solution for bigger problem. Dynamic Programming: problem reduced to multiple (typically) dependent or overlapping subproblems. Use memoization to avoid recomputation of common solutions leading to iterative bottomup algorithm. Chekuri CS473ug Fibonacci Numbers Fibonacci Numbers Fibonacci numbers defined by recurrence: F ( n ) = F ( n 1) + F ( n 2) and F (0) = 0 , F (1) = 1 . These numbers have many interesting and amazing properties. A journal The Fibonacci Quarterly ! F ( n ) = ( φ n (1 φ ) n ) / √ 5 where φ is the golden ratio (1 + √ 5) / 2 ’ 1 . 618. lim n →∞ F ( n + 1) / F ( n ) = φ Chekuri CS473ug Fibonacci Numbers Fibonacci Numbers Fibonacci numbers defined by recurrence: F ( n ) = F ( n 1) + F ( n 2) and F (0) = 0 , F (1) = 1 . These numbers have many interesting and amazing properties. A journal The Fibonacci Quarterly ! F ( n ) = ( φ n (1 φ ) n ) / √ 5 where φ is the golden ratio (1 + √ 5) / 2 ’ 1 . 618. lim n →∞ F ( n + 1) / F ( n ) = φ Question: Given n , compute F ( n ). Chekuri CS473ug Fibonacci Numbers Recursive Algorithm for Fibonacci Numbers Fib(n): if (n = 0) return 0 else if (n = 1) return 1 else return Fib(n1) + Fib(n2) Chekuri CS473ug Fibonacci Numbers Recursive Algorithm for Fibonacci Numbers Fib(n): if (n = 0) return 0 else if (n = 1) return 1 else return Fib(n1) + Fib(n2) Running time? Let T ( n ) be the number of additions in Fib(n). Chekuri CS473ug Fibonacci Numbers Recursive Algorithm for Fibonacci Numbers Fib(n): if (n = 0) return 0 else if (n = 1) return 1 else return Fib(n1) + Fib(n2) Running time? Let T ( n ) be the number of additions in Fib(n)....
View
Full
Document
This note was uploaded on 01/22/2012 for the course CS 573 taught by Professor Chekuri,c during the Fall '08 term at University of Illinois, Urbana Champaign.
 Fall '08
 Chekuri,C
 Algorithms, C Programming, Recursion

Click to edit the document details