+ All Categories
Home > Documents > lec-1 (1)

lec-1 (1)

Date post: 13-Sep-2015
Category:
Upload: aanand-rishabh-daga
View: 212 times
Download: 0 times
Share this document with a friend
Description:
Lecture on Algorithms
Popular Tags:
21
Ragesh Jaiswal CSE, IIT Delhi CSL 356: Analysis and Design of Algorithms
Transcript
  • Ragesh Jaiswal

    CSE, IIT Delhi

    CSL 356: Analysis and Design of

    Algorithms

  • Greedy Algorithms

  • Greedy Algorithms: Introduction

    A local (greedy) decision rule leads to a globally optimal solution.

    Two ways to show the above property:

    1. Greedy stays ahead.

    2. Exchange argument

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Candidate greedy choices:

    Earliest start time

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Candidate greedy choices:

    Earliest start time

    Smallest duration

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Candidate greedy choices:

    Earliest start time

    Smallest duration

    Least overlapping

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Candidate greedy choices:

    Earliest start time

    Smallest duration

    Least overlapping

    Earliest finish time

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Greedy Algorithm:

    GreedySchedule

    While is not empty - Choose an interval ((), ()) from that has the smallest value of () - Delete all intervals in that overlap with ((), ())

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Greedy Algorithm:

    GreedySchedule

    While is not empty - Choose an interval ((), ()) from that has the smallest value of () - Delete all intervals in that overlap with ((), ())

    Question: Let denote some optimal subset and be the subset given by GreedySchedule. Can we show that = ?

  • Greedy Algorithms: Example

    Can we show that || = ||?

    Yes we can! We will use the greedy stays ahead method to show

    this.

    Proof: Let 1, 2, , be the sequence of requests that GreedySchedule picks and 1, 2, , be the requests in sorted by finishing time.

    Claim: (1) (1)

  • Greedy Algorithms: Example

    Can we show that || = ||?

    Yes we can! We will use the greedy stays ahead method to show

    this.

    Proof: Let 1, 2, , be the sequence of requests that GreedySchedule picks and 1, 2, , be the requests in sorted by finishing time.

    Claim: (1) (1)

    Claim: If (1) (1), (2) (2), , (1) (1), then () ().

  • Greedy Algorithms: Example

    Can we show that || = ||?

    Yes we can! We will use the greedy stays ahead method to show

    this.

    Proof: Let 1, 2, , be the sequence of requests that GreedySchedule picks and 1, 2, , be the requests in sorted by finishing time.

    Claim: (1) (1)

    Claim: If (1) (1), (2) (2), , (1) (1), then () ().

    GreedySchedule could not have stopped after

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Greedy Algorithm:

    GreedySchedule

    While is not empty - Choose an interval ((), ()) from that has the smallest value of () - Delete all intervals in that overlap with ((), ())

    Running time:

  • Greedy Algorithms: Example

    Interval scheduling: Given a set of intervals of the form ((), ()), find the largest subset of non-overlapping intervals.

    Greedy Algorithm:

    GreedySchedule

    While is not empty - Choose an interval ((), ()) from that has the smallest value of () - Delete all intervals in that overlap with ((), ())

    Running time: ( log )

  • Greedy Algorithms: Example

    Fractional Knapsack: You are a thief and you have a sack of

    size . There are divisible items. Each item has a volume () and total value (). How will you maximize your profit?

    Greedy strategies:

    Pick items with largest value first.

    W = 50

    20 50 30

    10

    50 25 60 30

  • Greedy Algorithms: Example

    Fractional Knapsack: You are a thief and you have a sack of size . There are divisible items. Each item has a volume () and total value (). How will you maximize your profit?

    Greedy strategies:

    Pick items with largest value first.

    Pick items with smallest volume first.

    W = 50

    20 50 30

    10

    50 25 60 30

  • Greedy Algorithms: Example

    Fractional Knapsack: You are a thief and you have a sack of size . There are divisible items. Each item has a volume () and total value (). How will you maximize your profit?

    Greedy strategies:

    Pick items with largest value first.

    Pick items with smallest volume first.

    Pick items with largest cost per unit volume.

    W = 50

    20 50 30

    10

    50 25 60 30

  • Greedy Algorithms: Example

    Fractional Knapsack: You are a thief and you have a sack of size . There are divisible items. Each item has a volume () and total value (). How will you maximize your profit?

    W = 50

    20 50 30

    10

    50 25 60 30

    GreedySteal

    While Sack is not full

    - Choose an item from that has the largest cost per unit volume - Put as much as you can of this item in the sack and delete from

  • Greedy Algorithms: Example

    Consider items in decreasing order of the cost per unit

    volume value.

    Let (1, , ) be the volume of items in the sack chosen by GreedySteal.

    Let (1, , ) be some optimal volume of items that maximizes the profit.

    Claim: For all , 1 1 + + 1 1 + +

  • End

    Problems to think about:

    1. Consider the fractional-knapsack problem. Think of an exchange

    argument to prove that the greedy algorithm gives the optimal

    solution.


Recommended