




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
The concept of greedy algorithms and their application to the activity selection problem. Greedy algorithms make the choice that looks best at each moment, and while they don't always lead to optimal solutions, they do for many problems, including activity selection and the fractional knapsack problem. An example of the greedy activity selector algorithm and analyzes its optimality.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Jared Saia University of New Mexico
“Greed is Good” - Michael Douglas in Wall Street
Imagine you are given the following set of start and stop times for activities
(note: code for this algorithm is in section 16.1)
The problem:
(This is called the 0-1 knapsack problem because each item is either taken or not taken, the thief can not take a fractional amount)
≥ (xi − x′ i) vk wk
∑^ n i=
xivi −
∑^ n i=
x′ ivi (1)
∑^ n i=
(xi − x′ i) ∗ vi (2)
∑^ n i=
(xi − x′ i) ∗ wi
( vi wi
) (3)
∑^ n i=
(xi − x′ i) ∗ wi
( vk wk
) (4)
( vk wk
) ∗
∑^ n i=
(xi − x′ i) ∗ wi (5)
≥ 0 (6)
(xi − x′ i) ∗ wi =
∑^ n i=
xiwi −
∑^ n i=
x′ iwi (7)
= W − W ′^ (8) ≥ 0. (9)
Consider the inequality:
(xi − x′ i) vi wi
≥ (xi − x′ i) vk wk