15 - Greedy Algorithms Data Structures and Algorithms...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Greedy Algorithms Data Structures and Algorithms Andrei Bulatov
Background image of page 1

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

View Full DocumentRight Arrow Icon
“Greed … is good. Greed is right. Greed works.” “Wall Street” Algorithms – Greedy Algorithms 15-2
Background image of page 2
Algorithms – Greedy Algorithms 15-3 Interval Scheduling Consider the following problem ( Interval Scheduling ) There is a group of proposed talks to be given. We want to schedule as many talks as possible in the main lecture room. Let be the talks, talk begins at time and ends at time . (No two lectures can proceed at the same time, but a lecture can begin at the same time another one ends.) We assume that . m t t t , , , 2 1 K j t j b j e m e e e K 2 1 9:00 10:00 11:00 12:00 1 t 2 t 3 t 5 t 4 t 6 t 7 t 8 t
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithms – Greedy Algorithms 15-4 Greedy Algorithm Greedy algorithm: At every step choose a talk with the earliest ending time among all those talks that begin after all talks already scheduled end. 9:00 10:00 11:00 12:00 1 t 2 t 3 t 5 t 4 t 6 t 7 t 8 t
Background image of page 4
Algorithms – Greedy Algorithms 15-5 Greedy Algorithm (cntd) Input : Set R of proposed talks Output : Set A of talks scheduled in the main lecture hall set A:= while R ≠∅ choose a talk i R that has the smallest finishing time set A:=A {i} delete all talks from R that are not compatible with i endwhile return A Theorem The greedy algorithm is optimal in the sense that it always schedules the most talks possible in the main lecture hall.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Algorithms – Greedy Algorithms 15-6 Optimality Proof By induction on n we prove that if the greedy algorithm schedules n talks, then it is not possible to schedule more than n talks. Basis step. Suppose that the greedy algorithm has scheduled only one talk, . This means that every other talk starts before , and ends after . Hence, at time each of the remaining talks needs to use the lecture hall. No two talks can be scheduled because of that. Inductive step. Suppose that if the greedy algorithm schedules k talks, it is not possible to schedule more than k talks. We prove that if the algorithm schedules k + 1 talks then this is the optimal number. 1 t 1 e 1 e 1 e
Background image of page 6
Algorithms – Greedy Algorithms 15-7 Optimality (cntd) Suppose that the algorithm has selected k + 1 talks. First, we show that there is an optimal scheduling that contains
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

15 - Greedy Algorithms Data Structures and Algorithms...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online