























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Prof. Aashika Yuyutsu at Shree Ram Swarup College of Engineering and Management for Complexity of Algorithms course. Its main points are: Fundamental, Solution, Techniques, Greedy, Algorithms, Natural, Divide, Conquer, Optimization, Problem
Typology: Slides
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































At the conclusion of this set of lecture notes, you should:
An optimization problem is a problem that involves searching for a configuration that minimizes or maximizes some objective function.
An optimization problem is a problem that involves searching for a configuration that minimizes or maximizes some objective function.
The greedy method solves (or tries to solve) a given optimization problem by going through a sequence of (feasible) choices.
An optimization problem is a problem that involves searching for a configuration that minimizes or maximizes some objective function.
The greedy method solves (or tries to solve) a given optimization problem by going through a sequence of (feasible) choices. The sequence starts from a well-understood starting configuration, and then iteratively makes the decision that seems best from all those that are currently possible. Problems that have a greedy solution are said to possess the greedy-choice property.
There are many problems that can be solved using a greedy method, such as I (^) Fractional Knapsack Problem I (^) Interval Scheduling I (^) Task Scheduling I (^) Minimum Spanning Trees (e.g. Kruskal’s Algorithm, Prim’s Algorithm) I (^) Shortest Paths (e.g. Dijkstra’s Algorithm, Bellman-Ford Algorithm) I (^) Change Making (for some (but not all) sets of coins) I (^) Maximum Spacing k-clustering I (^)...
Let S be a set of n items, where each item i has a positive benefit bi and a positive weight wi.
Let S be a set of n items, where each item i has a positive benefit bi and a positive weight wi. Goal : Find the maximum benefit subset that does not exceed total weight W.
Let S be a set of n items, where each item i has a positive benefit bi and a positive weight wi. Goal : Find the maximum benefit subset that does not exceed total weight W. In a FKP we are allowed to take arbitrary fractions, xi , of each item, i.e. the solution is a set of values xi such that
0 ≤ xi ≤ wi for all i, and ∑
i∈S
xi ≤ W.
The total benefit of the items taken is determined by the sum ∑
i∈S
bi (xi /wi ).
The general method for the FKP is to compute the value index for each item i, where this is defined as
vi =
bi wi
The general method for the FKP is to compute the value index for each item i, where this is defined as
vi =
bi wi
Then we select items to include in the knapsack, starting with the highest value index.
Using a heap (storing the maximum at the root), we can compute the value indices and build the heap in O(n log n) time. Then, each greedy choice (which removes an item with the greatest remaining value index) requires O(log n) time.
Input: Set S of items, item i has weight wi and benefit bi , maximum total weight W. Output: Amount xi of each item to maximize the total benefit. 1 for i ← 1 to |S| do 2 xi ← 0 3 vi ← bi /wi 4 Insert (vi , i) into a heap H (max value index at root). 5 w ← 0 6 while w < W do 7 Remove the max value from H. 8 a ← min{wi , W − w} 9 xi ← a 10 w ← w + a
The { 0 , 1 }-Knapsack Problem is very similar to the Fractional Knapsack Problem.
The significant difference is that in the { 0 , 1 } version, we are not allowed to take fractional amounts of the items, either we take the entire item, or leave it behind.
The { 0 , 1 }-Knapsack Problem is very similar to the Fractional Knapsack Problem.
The significant difference is that in the { 0 , 1 } version, we are not allowed to take fractional amounts of the items, either we take the entire item, or leave it behind.
A Greedy Method does not (in general) find an optimal solution of the { 0 , 1 }-Knapsack Problem.