0% found this document useful (0 votes)
9 views20 pages

L01 Introduction

Uploaded by

Gio Villa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

L01 Introduction

Uploaded by

Gio Villa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Design and Analysis of

Algorithms

Lecture 1
Prof. Piotr Indyk
Course information
• Course web site: Canvas (+Piazza, Gradescope)
• Staff
• Prerequisites: intro to algorithms, discrete maths
– If not fulfilled, email [email protected]
• Lectures &Recitations
– Lectures Tu/Thu, Recitations Fri
• Problem sets
– Out on Thursdays, in on Wednesdays
– Warmups due in 1+1 days
– 3x2 late days for psets, otherwise need a request from S3
– Discount 2 lowest pset scores, same for warmups
• Describing algorithms
• Grading policy
– Psets 20%; Quiz 1 25%; Quiz 2 25%; Final 30%
• Collaboration policy
– collaboration good, copying bad
What is this class about ?
• 6.006: Algorithm literacy
• 6.046: The art/craft of algorithms
• Techniques:
• Divide and conquer
• Randomization
• Amortized Analysis
• Greedy Approach
• Incremental Improvement
• Linear Programming
• Dynamic Programming
• Continuous Optimization
• Reductions
• Approximation Algorithms
• Computing Models
• Online algorithms
• Streaming algorithms
• Sketching algorithms
• Parallel/Distributed algorithms
Today: three shades of interval
scheduling
• Three formalizations of class scheduling
• Unweighted interval scheduling
• Weighted interval scheduling
• Job interval scheduling
• A guided tour through many of the concepts
from the previous slides

Moral: similar problems can have very


different solutions and complexity
Unweighted Interval Scheduling
Unweighted Interval Scheduling
6.046 6.036

6.003

• n “requests” modeled as intervals ri=[ai,bi]


• Two intervals ri and rj are compatible if they
do not intersect
• Goal: select the maximum number of
compatible intervals
• Ideas how to solve this problem ?
Greedy

Meta-algorithm:
• Use a “simple rule” to pick the next ri =[ai,bi]
• Add ri to the solution, discard all intervals that are
incompatible
• Repeat

Which “simple rule” to use ?

“Interval that finishes first” (smallest bi)

Intuition: such an interval leaves most options for the


future
Proof

Rule: In each step, select interval that finishes first


(smallest bi)
Theorem: greedy algorithm with this rule returns
largest possible solution.
Proof by ”exchangeability argument”:
•Let r1, r2, … be the intervals selected by greedy (in this order); let r’1, r’2,
… be an optimum solution (left to right)
•Suppose that ri is the first interval that it is not in OPT, which instead
contains r’i
•We have bi <= b’i (by the selection rule), and b’i <= a’i+1, so r1, r2, … ri are
compatible with r’i+1,…,
•Therefore, we can replace r’i by ri in OPT
•Repeat this argument until OPT is transformed into greedy solution of the
same cardinality
Running time ?

Algorithm:
• Sort ri in the ascending order of bi O(n log n)
• Consider each interval ri in order, Or better via Radix Sort

remembering the last selected rj O(n)


• If ri compatible with rj, select ri

Total time: O(n) + sorting

More about greedy algorithms in


Lecture 8.
Weighted Interval Scheduling
Weighted Interval Scheduling
6.046 6.036

6.003

• Each interval ri=[ai,bi] has weight wi


• Goal: select a set of compatible intervals
with the largest weight

• Ideas ?
• We will use dynamic programming
• Recurrence with few subproblems
Dynamic programming

• Sort all intervals ri=[ai,bi] by their start time ai, so that


a1<=a2 <= …
• Recursive formula for OPT (r1,….rn)
• Should r1 be included in the solution ?
• If no:
OPT (r1,….rn)=OPT (r2,….rn)
• If yes:
OPT (r1,….rn)=w1+ OPT (rt,….rn)
where rt,….rn are all requests compatible with r1
• Overall:
OPT (r1,….rn)=max(OPT (r2,….rn), w1+ OPT (rt,….rn))
Dynamic programming ctd

OPT (r1,….rn)=max(OPT (r2,….rn), w1+ OPT (rt,….rn))

• Subproblems: one for each suffix ri….rn, so n overall


• Time per subproblem:
• Need to find rt
– Linear scan: O(n)
– Binary search: O(log n)
• Overall time: n*O(log n) = O(n log n)
The rest of the material is
optional, as it was covered only
briefly during the class

L1.14
Job Interval Scheduling
Job Interval Scheduling

• Each job consists of k possible intervals


• Goal: select the largest set of nonconflicting
intervals, at most one per job.
• The problem is NP-complete
Complexity classes
P
Graph
connectivity Edit distance
rting
So
O(n)
O(n log n) O(n2)

P: problems solvable in polynomial time, i.e., O(nc) for some c>0


NP: problems verifiable in polynomial time
All problems in P are also in NP, but there could be others
• E.g., SAT: is a given formula satisfiable ?
Is P=NP ? A million dollar question! More in lectures 15-16
NP
P NP- vs. P=NP
complete
Job Interval Scheduling

• Each job consists of k possible intervals


• Goal: select the largest set of nonconflicting
intervals, at most one per job.
• The problem is NP-complete
• A greedy algorithm finds a 2-approximation
• A better algorithm yields e/(e-1)-approximation
[Chuzhoy Ostrovsky Rabani’06]
• More on approximation algorithms in Lectures 17-
18
Wrapping Up
• Three formalizations of class scheduling lead
to very different algorithms/complexity:
• Unweighted interval scheduling: O(n+sorting) via
greedy
• Weighted interval scheduling: O(n log n) via DP
• Job interval scheduling: NP-complete,
approximation algorithms

• All of this and more in the rest of the course!


Acks
• Images From Wikimedia:
• Paint Brush - The Noun Project.svg icon from the Noun Project
• Vincent van Gogh: The Starry Night

You might also like