Download presentation

Presentation is loading. Please wait.

Published byAlanna Maslyn Modified over 3 years ago

1
Algorithm Design approaches Dr. Jey Veerasamy

2
Petrol cost minimization problem You need to go from S to T by car, spending the minimum for petrol. 2 ST

3
Quick-sort

4
Merge-sort

5
Divide & Conquer - characteristics

6
# of stops minimization problem Similar to petrol cost minimization problem, but we are minimizing # of stops. ST

7
Activity selection problem

8
Fractional knapsack problem Gold powder, silver powder, … Thief has limited weight capacity

9
Greedy approach - characteristics

10
10 Fibonacci number problem Definition of Fibonacci number: F(1) = 1 F(2) = 2 F(n) = F(n-1) + F(n-2), when n > 2 Recursive solution using D&C approach: int f(int n) { if (n == 1) return 1; else if (n == 2) return 2; else return f(n-1) + f(n-2); }

11
11 D&C Solution for F(6) F(1)F(2) F(3)F(2) F(4) F(3) F(5) F(2)F(1) F(6) F(1)F(2) F(3)F(2) F(4) Several subproblems are solved repeatedly - Not an efficient approach.

12
12 DP solution for F(6) F(1)F(2)F(3)F(4)F(5)F(6) DP uses a table and bottom-up approach (note that D&C used top-down approach): int fib(int n) { int f[n+1]; f[1] = 1; f[2] = 2; for (i=3 ; i<= n ; i++) f[i] = f[i-1]+f[i-2]; return f[n]; } Computations are NOT repeated!

13
Knapsack problem Individual pieces with specific weights, thief wants to know whether there is an exact match for his weight limit.

14
Dynamic programming - characteristics

Similar presentations

OK

Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.

Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Ppt on acid bases and salts for class 7 Appt only salon Ppt on principles of peace building support office Download ppt on strings in c language Ppt on earthquake free download Download ppt on acid bases and salts for class 10 Ppt on tb treatment Ppt on contact management system Ppt on complete c language Ppt on endangered and extinct species in india