dynamic programming biostatistics 615 815 lecture 9
play

Dynamic Programming Biostatistics 615/815 Lecture 9: . . . . . - PowerPoint PPT Presentation

. . February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang February 3rd, 2011 Hyun Min Kang Dynamic Programming Biostatistics 615/815 Lecture 9: . . . . . . Summary . . Edit Distance MTP Fibonacci Introduction . . .


  1. . . February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang February 3rd, 2011 Hyun Min Kang Dynamic Programming Biostatistics 615/815 Lecture 9: . . . . . . Summary . . Edit Distance MTP Fibonacci Introduction . . . . . . . . 1 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  2. . . good performance . Key components . . . . . . . . Hash function h x key mapping key onto smaller ’addressible’ space H Total required memory is the possible number of hash values Good hash function minimize the possibility of key collisions Collision-resolution strategy, when h k h k . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . . . . . . . . . . . . Introduction Fibonacci MTP Edit Distance . Summary Recap: Hash Tables . Key features . . . . 2 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Θ(1) complexity for Insert , Search , and Remove • Requires large memory space than the actual content for maintainng • But uses much smaller memory than direct-addres tables

  3. . . . . . good performance . Key components . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . . . MTP . . . . . . . . Introduction Fibonacci . 2 / 34 Edit Distance Recap: Hash Tables . . Summary Key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Θ(1) complexity for Insert , Search , and Remove • Requires large memory space than the actual content for maintainng • But uses much smaller memory than direct-addres tables • Hash function • h ( x . key ) mapping key onto smaller ’addressible’ space H • Total required memory is the possible number of hash values • Good hash function minimize the possibility of key collisions • Collision-resolution strategy, when h ( k 1 ) = h ( k 2 ) .

  4. . MTP February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang Recap: Illustration of ChainedHash Summary . Edit Distance 3 / 34 . Fibonacci Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  5. . . . . . . . Double Hashing . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . . . MTP . . . . . . . . Introduction . Fibonacci Edit Distance Summary Probing strategies . Recap : Open hash 4 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Linear probing • Quadratic probing • Double hashing • h ( k , i ) = ( h 1 ( k ) + ih 2 ( k )) mod m • The probe sequence depends in two ways upon k . • For example, h 1 ( k ) = k mod m , h 2 ( k ) = 1 + ( k mod m ′ ) • Avoid clustering problem • Performance close to ideal scheme of uniform hashing.

  6. . Today February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang . . . . . . . . Dynamic Programming . . Summary Introduction . . . . . . . . . MTP Fibonacci Edit Distance 5 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Fibonacci numbers • Manhattan tourist problems • Edit distance problem

  7. . . February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang until they become trivial. These algorithms divide a problem into smaller and disjoint subproblems . . . . . . . . . Good examples of divide and conquer algorithms Recap: Divide and conquer algorithms Introduction . . . . . . . . Summary 6 / 34 MTP Fibonacci Edit Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • TowerOfHanoi • MergeSort • QuickSort • BinarySearchTree algorithms

  8. int fibonacci(int n) { if ( n < 2 ) return n; else return fibonacci(n-1)+fibonacci(n-2); } . . . . . A recursive implementation of fibonacci numbers . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . 7 / 34 . . . . . . . . . . Introduction Fibonacci MTP Edit Distance . Summary . A divide-and-conquer algorithms for Fibonacci numbers Fibonacci numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  F n − 1 + F n − 2 n > 1  F n = 1 n = 1 0 n = 0 

  9. . . . . . . . A recursive implementation of fibonacci numbers . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . 7 / 34 . . . . . . . . . . Introduction Fibonacci MTP . Edit Distance Summary . Fibonacci numbers . A divide-and-conquer algorithms for Fibonacci numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . .  F n − 1 + F n − 2 n > 1  F n = 1 n = 1 0 n = 0  int fibonacci(int n) { if ( n < 2 ) return n; else return fibonacci(n-1)+fibonacci(n-2); }

  10. . Performance of recursive Fibonacci February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang . . . . . . . . Computational time . . Summary Introduction . . . . . . . . . MTP Fibonacci Edit Distance 8 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . • 4.4 seconds for calculating F 40 • 49 seconds for calculating F 45 • ∞ seconds for calculating F 100 !

  11. . MTP February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang What is happening in the recursive Fibonacci Summary . Edit Distance 9 / 34 . Fibonacci Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  12. . Edit Distance February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang The time complexity is exponential . Time complexity of redundant Fibonacci Summary . 10 / 34 MTP Fibonacci Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . T ( n ) = T ( n − 1) + T ( n − 2) T (1) = 1 T (0) = 1 T ( n ) = F n +1

  13. . MTP February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang . Summary . Edit Distance A non-redundant Fibonacci 11 / 34 Fibonacci . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . int fibonacci(int n) { int* fibs = new int[n+1]; fibs[0] = 0; fibs[1] = 1; for(int i=2; i <= n; ++i) { fibs[i] = fibs[i-1]+fibs[i-2]; } int ret = fibs[n]; delete [] fibs; return ret; }

  14. . . February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang Key idea in non-redundant Fibonacci Summary . Edit Distance MTP Fibonacci Introduction . . . . . . . . 12 / 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Each F n will be reused to calculate F n +1 and F n +2 • Store F n into an array so that we don’t have to recalculate it

  15. . MTP February 3rd, 2011 Biostatistics 615/815 - Lecture 9 Hyun Min Kang . Summary . Edit Distance A recursive, but non-redundant Fibonacci 13 / 34 Fibonacci . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . int fibonacci(int* fibs, int n) { if ( fibs[n] > 0 ) { return fibs[n]; // reuse stored solution if available } else if ( n < 2 ) { return n; // terminal condition } fibs[n] = fibonacci(n-1) + fibonacci(n-2); // store the solution once computed return fibs[n]; }

  16. . . . . . . . . . . According to wikipedia... ”The word ’dynamic’ was chosen because it sounded impressive, not because how the method works” . Examples of dynamic programming . . . . . . . . Shortest path finding algorithms DNA sequence alignment Hidden markov models Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 Why dynamic programming? 14 / 34 . Dynamic programming . . . . . . . . Introduction Fibonacci MTP Edit Distance . Summary . Key components of dynamic programing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Problems that can be divided into subproblems • Overlapping subproblems - subproblems share subsubproblems • Solves each subsubproblem just once and then saves its answer

  17. . . . . . . . . . . According to wikipedia... ”The word ’dynamic’ was chosen because it sounded impressive, not because how the method works” . Examples of dynamic programming . . . . . . . . Shortest path finding algorithms DNA sequence alignment Hidden markov models Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 Why dynamic programming? 14 / 34 . Dynamic programming . . . . . . . . Introduction Fibonacci MTP Edit Distance . Summary . Key components of dynamic programing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Problems that can be divided into subproblems • Overlapping subproblems - subproblems share subsubproblems • Solves each subsubproblem just once and then saves its answer

  18. . . Why dynamic programming? . . . . . . . . According to wikipedia... ”The word ’dynamic’ was chosen because it sounded impressive, not because how the method works” Examples of dynamic programming . . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 9 February 3rd, 2011 . 14 / 34 Edit Distance Dynamic programming . . . . . . Introduction Fibonacci MTP . . Summary . Key components of dynamic programing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . • Problems that can be divided into subproblems • Overlapping subproblems - subproblems share subsubproblems • Solves each subsubproblem just once and then saves its answer • Shortest path finding algorithms • DNA sequence alignment • Hidden markov models

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend