Greedy Algorithms: CS 306 Lecture notes

Computer Algorithms II Lecture Notes

28 October 2008 • Greedy Algorithms


Outline

A Scheduling Problem

Exhaustive Search

schedule(presentations)

  schedlue = { }

  for i = 1 to 2size(presentations) - 1
    s = get-schedue(i, presentations)
    if valid(s) ∧ size(s) > size(schedule)
      schedule = s

  return schedule

Faster Scheduling

An Alterntive Scheduler

  1. Order the presentations by increasing finish time.

  2. Scan the ordered presentations by increasing finish time.

  3. Always schedule the next earliest finishing non-conflicting presentation.

a scheduling problem

Does It Work?

Does It Work??

Does It Work???

Greedy Algorithms

greed(p)
  solution = { }
  while choices-left(p)
    solution ∪= best-choice(p)
  return solution

Greedy Algorithm Design

Example

schedule(p[])

  schedule = { 1 }
  last = 1

  for next = 2 to p.size()
    if p[last].end ≤ p[next].start
      schedule ∪= { next }
      last = next

  return schedule

Greed Advantages

But...

Greed Disadvantages

Greedy Problems

Greedy Conditions

Summary

References


This page last modified on 26 October 2008.

Creative
    Commons License