# lec22 - CS C341 I S C361 Data Structures Algorithms...

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

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

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

View Full Document
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
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

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

View Full Document
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); }
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;

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

View Full Document
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?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/07/2011 for the course CS 123 taught by Professor Murali during the Spring '11 term at Birla Institute of Technology & Science, Pilani - Hyderabad.

### Page1 / 19

lec22 - CS C341 I S C361 Data Structures Algorithms...

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

View Full Document
Ask a homework question - tutors are online