# 15 - Greedy Algorithms Data Structures and Algorithms...

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

Greedy Algorithms Data Structures and Algorithms Andrei Bulatov

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

View Full Document
“Greed … is good. Greed is right. Greed works.” “Wall Street” Algorithms – Greedy Algorithms 15-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

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

View Full Document
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
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.

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

View Full Document
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
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/19/2009 for the course CS CMPT 307 taught by Professor A.bulatov during the Fall '09 term at Simon Fraser.

### 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
Ask a homework question - tutors are online