lec22 - 2/7/11 2/7/11 CS C341 / I S C361 Data Structures...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 2/7/11 Sundar B. CS C341 / I S C361 Data Structures & Algorithms Algorithm Design Techniques Bottom-up Design Dynamic Programming - Examples - Fibonacci sequence - 0,1 Knapsack 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Top Down Design vs. Bottom Up Design 22 Strategy: Combine solutions Start: Atomic solutions End: Solution to given problem Weakness: Problem structure must be analyzed apriori If not, what happens? Top Down Design Bottom Up Design Strategy: Divide problem Start: Given problem End: Atomic problems Strength: Easy to frame solutions for new problems
Background image of page 2
2/7/11 Sundar B. Divide and Conquer vs. Dynamic Programming 33 Dynamic Programming is a Top Down Design Bottom Up Design Divide and Conquer is a special case of
Background image of page 3

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Example – Fibonacci Sequence – Top Down 44 {34E06C73-8132-4275-BF13-BF6BD436AF 3} F(N) F(N-1) F(N-2) F(N-3) F(N-4) F(N) { if (N<=1) return 1; else return F(N-1) + F(N- 2); }
Background image of page 4
2/7/11 Sundar B. Example – Fibonacci Sequence – 55 F(N) // assume array fib of <done: boolean, val: int> // initialize: for i=0 to N fib[i]. done=false // fib[0].val = fib[1].val = 1; // fib[0].done = fib[1].done = true; { if (fib[N].done) return fib[N].val; else { fib[N].val = F(N-1) + F(N-2); fib[N].done = true; return fib[N].val;
Background image of page 5

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Example – Fibonacci Sequence – DP Known (Atomic) Solutions: F(0) = 1; F(1) = 1; Recursive structure: F(j) = F(j-1) + F(j-2) for j>=2 i.e. using F(0), and F(1) we can compute F(2) using F(1) and F(2) we can compute F(3) … 66 F(N) // assume array fib[0. .N] of int { fib[0] = fib[1] = 1; // atomic solutions for (j=2; j<=N; j++) fib[j] = fib[j-1] + fib[j-2]; return fib[N]; } Straightforward conversion from Memoized version: Time Complexity? Space Complexity?
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

lec22 - 2/7/11 2/7/11 CS C341 / I S C361 Data Structures...

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

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