0% found this document useful (0 votes)
85 views

GDB cs502

i) Greedy algorithms make locally optimal choices at each step without considering future consequences in an effort to find a global optimum. However, greedy approaches do not always find the best solution. ii) Dynamic programming breaks problems into overlapping subproblems that are solved once and stored for future use, reducing exponential time complexity to polynomial. iii) Dynamic programming is preferred over greedy for solving the 0-1 knapsack problem because greedy does not ensure an optimal solution, as items must be taken whole or not at all, whereas dynamic programming guarantees finding the optimal solution through its principle of optimality.

Uploaded by

MH Amber
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

GDB cs502

i) Greedy algorithms make locally optimal choices at each step without considering future consequences in an effort to find a global optimum. However, greedy approaches do not always find the best solution. ii) Dynamic programming breaks problems into overlapping subproblems that are solved once and stored for future use, reducing exponential time complexity to polynomial. iii) Dynamic programming is preferred over greedy for solving the 0-1 knapsack problem because greedy does not ensure an optimal solution, as items must be taken whole or not at all, whereas dynamic programming guarantees finding the optimal solution through its principle of optimality.

Uploaded by

MH Amber
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Greedy Approach

i) Locally optimal decisions, can't change once made.


ii) Efficient
iii) way of implementation is easy
iv) The solution is expected to be optimal
v) Every problem may not have greedy solution.

Basically A greedy algorithm works in Two phases. At each phase:


• You take the best you can get right now, without regard for future consequences and future
results.
• You hope that by choosing a local optimum at each step, you will end up at a global optimum
sometimes for some problems, greedy approach always gets optimum. For others, greedy finds
good, but not always
best. If so, it is called a greedy heuristic, or approximation. For still others, greedy approach can
do very poorly.

Dynamic programming
i) Decompose problem into sub-problems like divide and conquer
ii) Sub-problems are dependent
iii) Record results of smaller sub-problems
iv) Re-use it for further occurrence
v) Mostly reduces complexity exponential to polynomial.

In contrast of dynamic programming and greedy approach, the i prefer for the solution of 0/1
knapsack problem is dynamic programming.
Reason behind this Algorithm:
In 0-1 Knapsack, items cannot be broken which means the thief should take the item as a whole
or should leave it.
0-1 Knapsack cannot be solved by Greedy approach. it does not ensure an optimal solution.
I also know that the greedy algorithm works for fractional knapsack problem because the
globally optimal choice is to take the item with the largest value. The greedy algorithm only
works because we can “cut up” items to fill the rest of the knapsack, we cannot do that in the 0–
1 case.
The DM programing is guaranteed that Dynamic Programming will generate an optimal solution
using Principle of Optimality.
Dynamic programming is more efficient than Greedy. Greedy algorithm have a local choice of
the sub-problems whereas Dynamic programming would solve the all sub-problems and then
select one that would lead to an optimal solution.

You might also like