DP - CSE 3101 Prof. Andy Mirzaian STUDY MATERIAL: [CLRS]...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 3101 Prof. Andy Mirzaian STUDY MATERIAL: [CLRS] chapter 15 Lecture Note 6 Algorithmics Animation Workshop: Optimum Static Binary Search Tree TOPICS Recursion Tree Pruning by Memoization Recursive Back-Tracking Dynamic Programming Problems: Fibonacci Numbers Shortest Paths in a Layered Network Weighted Event Scheduling Knapsack Longest Common Subsequence Matrix Chain Multiplication Optimum Static Binary Search Tree Optimum Polygon Triangulation More Graph Optimization problems considered later Recursion Tree Pruning by Memoization Alice: We have done this sub-instance already, havent we? Bob: Did you take any memo of its solution? Lets re-use that solution and save time by not re-doing it. Alice: Thats a great time saver, since we have many many repetitions of such sub-instances! Re-occurring Sub-instances In divide-&-conquer algorithms such as MergeSort, an instance is typically partitioned into non-overlapping sub-instances (e.g., two disjoint sub-arrays). That results in the following property: For any two (sub) sub-instances, either one is a sub-instance of the other (a descendant in the recursion tree), or the two are disjoint & independent from each other. We never encounter the same sub-instance again during the entire recursion. If the sub-instances overlap, further down the recursion tree we may encounter repeated (sub) sub-instances that are in their common intersection. Example 1: The Fibonacci Recursion tree (see next slide). Example 2: Overlapping sub-arrays as sub-instances. Fibonacci Recursion Tree Algorithm F (n) if n {0,1} then return n return F(n-1) + F(n-2) end F(100) F(99) F(98) F(98) F(97) F(95) F(96) F(97) F(96) F(96) F(96) F(95) F(95) F(95) F(94) F(97) F(96) F(95) F(95) F(94) F(94) F(93) F(94) ). ( ) F ( ) n ( T 1 , n ) 1 ( 2 n ) 1 ( ) 2 n ( T ) 1 n ( T ) n ( T n n = = = +- +- = But only n+1 distinct sub-instances are ever called: F(0), F(1), , F(n-2), F(n-1), F(n). Why is it taking time exponential in n? Pruning by Memoization Algorithm Fib(n) for t 0 .. 1 do Memo[t] t for t 2 .. n do Memo[t] null initialize Memo[0..n] table return F( n) end Function F(n) recursion structure kept if Memo[n] = null then Memo[n] F(n-1) + F(n-2) memo feature added return Memo[n] end F(n-2) F(n) F(n-1) F(n-2) F(n-3) F(n-4) F(2) F(1) F(0) F(n-3) F(n-5) F(n-4) F(n-3) Nodes in recursion tree evaluated in post-order. Now all right sub-trees are pruned. Instead of re-solving a sub-instance, fetch its solution from the memo table Memo[0..n]. T(n) = (n). Time-space trade off. Memoization: Recursive vs Iterative Algorithm Fib(n) recursive top-down for t 0 .. 1 do Memo[t] t for t 2 .. n do Memo[t] null return F( n) end Function F(n) if Memo[n] = null then Memo[n] F(n-1) + F(n-2) return Memo[n] end Algorithm Fib(n) iterative bottom-up...
View Full Document

This note was uploaded on 04/17/2010 for the course CSE 3101 taught by Professor Andy during the Winter '10 term at York University.

Page1 / 121

DP - CSE 3101 Prof. Andy Mirzaian STUDY MATERIAL: [CLRS]...

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

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