cs340_09s_chapter10Part1 - CS340 In Chapter 10 algorithm...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS340 Algorithmic Design Techniques 10.3 Intro to Dynamic Programming CS340 Dynamic Programming 2 In Chapter 10 • algorithm design techniques – 10.1 Greedy algorithm s – 10.2 Divide and Conquer – 10.3 Dynamic programming – 10.4 Randomized algorithm s – 10.5 Backtracking algorithm s • Meta algorithms, not actual algorithms CS340 Dynamic Programming 3 In Chapter 10 • algorithm design techniques – 10.1 Greedy algorithm s • e.g.: Prim’s, Kruskal’s, Knapsack – 10.2 Divide and Conquer • e.g.: Merge Sort, Quick Sort – 10.3 Dynamic programming • e.g.: Dijkstra’s – 10.4 Randomized algorithm s – 10.5 Backtracking algorithm s CS340 Dynamic Programming 4 Optimization Problems • practical class of computational problems – For each problem instance – There are many feasible solutions (often exponential) – Each solution has a value (or cost) – The goal is to find a solution with the optimal value • For most of these, the best known algorithm runs in exponential time. • Industry would pay dearly to have faster algorithms. • For some of them, there are quick dynamic programming or greedy algorithms. • For the rest, you may have to consider acceptable solutions rather than optimal solutions CS340 Dynamic Programming 5 Dynamic programming • The word “programming” is historical and predates ‘computer programming’ • A very powerful, general tool for solving certain optimization problems • it is relatively easy to apply, it looks like magic until you have seen enough examples CS340 Dynamic Programming 6 Fibonacci numbers • 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … F(0) = 1; F(1) = 1; F(n) = F(n-1) + f(n-2) • How to compute F(n)?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS340 Dynamic Programming 7 A recursive algorithm function fib(n) if (n == 0 or n == 1) return 1; else return fib(n-1) + fib(n-2); What’s the time complexity? CS340 Dynamic Programming 8 • Time complexity between 2 n/2 and 2 n F( 9 ) F( 8 ) F( 7 ) F( 7 ) F( 6 ) F( 6 ) F( 5 ) F( 6 ) F( 5 ) F( 5 ) F( 4 ) F( 5 ) F( 4 ) F( 4 ) F( 3 ) O(1.6 n ) = F(n) CS340 Dynamic Programming 9 An iterative algorithm function fib(n) F[0] = 1; F[1] = 1; for i = 2 to n F[n] = F[n-1] + F[n-2]; Return F[n]; Time complexity? CS340 Dynamic Programming 10 • Problem with the recursive Fib algorithm: – Solve same subproblems many times! • Solutions: (1) pre-compute all subproblems that may be needed later (2) Compute on demand, but memorize the solution to avoid recomputing • Can you always speedup a recursive algorithm by making it an iterative algorithm? – e.g., Merge Sort CS340 Dynamic Programming 11 Shortest path problem • Find the shortest path from start to goal • An optimization problem start goal CS340 Dynamic Programming 12 Possible approaches • Brute-force algorithm – Enumerate all possible paths and compare – How many? • Greedy algorithm
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/26/2009 for the course CS 340 taught by Professor Bouvier,d during the Spring '09 term at Southern Illinois University Edwardsville.

Page1 / 11

cs340_09s_chapter10Part1 - CS340 In Chapter 10 algorithm...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online