Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed
Design & Analysis of Algorithms · Lecture 1 of 34 · 1:23:34
Lecture 1: Course Overview, Interval Scheduling
Study guide
What this lecture covers
This opening lecture of MIT's Design and Analysis of Algorithms course sets up the semester's central question: how small changes to a problem's constraints can move it between easy, harder-but-still-polynomial, and intractable. After a short logistics overview, Professor Devadas reviews the classes P and NP and what makes a problem NP-complete, then uses a single running example, scheduling requests on a resource, to show the same idea in action three times.
By the end, you can state the interval scheduling problem, explain why picking the request with the earliest finish time is provably optimal, see how adding weights turns the same problem into a dynamic programming exercise, and recognize why adding multiple non-identical machines pushes the problem into NP-completeness.
Key ideas
- P: the class of problems solvable in polynomial time, such as
O(V^2)shortest paths. - NP: problems whose proposed solutions can be verified in polynomial time, such as checking a Hamiltonian cycle.
- NP-complete: the hardest problems in NP; solving any one of them in polynomial time would solve all of NP in polynomial time.
- Interval scheduling: given requests each with a start and finish time on a single resource, select the largest compatible subset.
- Greedy algorithm template: repeatedly pick a request by a simple rule, reject everything incompatible with it, and recurse on what remains.
- Earliest finish time rule: among the rules tried (smallest interval, numeric order, fewest incompatibilities), only picking the request that finishes earliest is proven optimal, by induction on the size of the optimal solution.
- Weighted interval scheduling: when requests carry weights and you want maximum total weight rather than maximum count, the greedy rule fails and a dynamic programming solution is needed instead.
- Problem generalization and hardness: allowing multiple non-identical machines, where each request can only run on a subset of machines, turns the scheduling decision problem into an NP-complete one.
Walkthrough
Course overview and logistics (0:00)
The lecture opens with introductions (Devadas, Demaine, and Lynch as co-lecturers) and course logistics: 6.006 is a prerequisite, coursework runs through the Stellar website, and problem sets are worth 30% of the grade but carry a larger penalty for not attempting them. Devadas then previews the course's modules: divide and conquer, greedy algorithms, dynamic programming, network flow, intractability, and advanced topics such as distributed algorithms and cryptography.
P, NP, and NP-completeness (10:06)
Devadas frames the semester's theme: small changes to a problem statement can move it from an easy linear-time solution to something intractable. He reviews P as problems solvable in polynomial time, NP as problems whose solutions are verifiable in polynomial time (using the Hamiltonian cycle problem as an example), and NP-completeness as the property that a problem is both in NP and at least as hard as every other problem in NP. Reductions between problems are introduced as the tool for showing a new problem is hard.
Defining interval scheduling (17:07)
The problem is defined formally: a single resource, requests numbered 1 through n, each with a start time s_i and finish time f_i where s_i < f_i. Two requests are compatible if their intervals don't overlap (a shared boundary point counts as compatible). The goal is to select the largest compatible subset of requests, illustrated with a six-interval example where the answer is three.
Testing greedy selection rules (24:13)
Devadas defines the greedy template: pick a request by some rule, reject everything incompatible with it, repeat. Students propose several selection rules interactively: earliest finish time, numeric order, shortest interval, and fewest incompatible requests. Counterexamples drawn on the board eliminate every rule except earliest finish time, which survives every example tried.
Proving earliest finish time is optimal (41:36)
The lecture gives a full induction proof that the greedy algorithm using earliest finish time always produces a maximum-size compatible set. The proof inducts on the size K* of an optimal solution: the base case is a single interval, and the inductive step swaps the first interval of an assumed optimal solution for the greedy algorithm's first pick, shows the resulting schedule is still optimal, and then applies the inductive hypothesis to the smaller remaining problem to conclude the greedy schedule matches K* + 1.
Weighted interval scheduling by dynamic programming (1:01:56)
Adding a weight w_i to each request and asking for maximum total weight breaks the greedy rule, shown with a two-request counterexample. Devadas builds a dynamic programming solution instead: subproblems R(f_i) consist of requests starting no earlier than f_i, giving n subproblems total. The recursion tries every request i as the first pick and takes opt(R) = max over i of w_i + opt(R(f_i)), giving an O(n^2) algorithm (a faster O(n log n) version is left for section).
From polynomial to NP-complete (1:20:05)
The lecture closes by generalizing to multiple, non-identical machines, where each request can only run on a specified subset of machines. This small change makes the decision version of the problem ("can K requests be scheduled?") NP-complete, previewing the course's later treatment of approximation algorithms and exponential-time fallbacks for intractable problems.
Before you watch
- Review basic data structures, sorting, dynamic programming, and shortest-path algorithms from an introductory algorithms course (6.006 or equivalent), since this lecture assumes that background.
- Be ready to think about proofs by induction; the earliest-finish-time proof is done in full detail as a model for later problem sets.
Check your understanding
- Why does picking the request with the earliest finish time always leave room for at least as many future selections as any other first pick?
- In the induction proof, why is it valid to replace the first interval of an optimal solution with the greedy algorithm's first pick without changing the schedule's size?
- Why does the same greedy rule that works for unweighted interval scheduling fail once requests have different weights?
- What are the subproblems
R(f_i)in the weighted interval scheduling DP, and why do they not simply equal "all requests compatible with request i"? - What specific change to the interval scheduling problem moves it from polynomial time into NP-completeness?
Vocabulary
- algorithm (noun)
- A step-by-step method for solving a problem.
This course studies how to design and analyze an algorithm's performance. - polynomial time (noun)
- Running time that grows no faster than the input size raised to a fixed power.
Problems in P can be solved in polynomial time. - NP-complete (adjective)
- Describing the hardest problems whose solutions can be checked quickly, but for which no fast solving method is known.
Scheduling on multiple machines becomes NP-complete under certain conditions. - reduction (noun)
- A way of transforming one problem into another to show they are related in difficulty.
A reduction can prove a new problem is at least as hard as a known one. - verify (verb)
- To check that a proposed answer is correct.
A problem is in NP if you can verify a solution quickly. - interval scheduling (noun)
- The problem of choosing the largest set of non-overlapping time slots from a list.
Interval scheduling asks how many compatible requests can be accepted. - compatible (adjective)
- Not overlapping or conflicting with each other.
Two intervals are compatible if they don't share any time. - greedy algorithm (noun)
- An algorithm that makes the locally best choice at each step, hoping it leads to the best overall result.
A greedy algorithm picks requests one at a time by a simple rule. - induction (noun)
- A method of proof that shows something is true for a base case, then shows it stays true as you build up.
The proof uses induction on the size of the optimal solution. - counterexample (noun)
- A specific case that shows a claimed rule or pattern is false.
A counterexample shows the shortest-interval rule doesn't always work. - dynamic programming (noun)
- A method of solving a problem by breaking it into overlapping subproblems and reusing their solutions.
Weighted interval scheduling is solved with dynamic programming. - subproblem (noun)
- A smaller version of the original problem, used to build up the full solution.
Each subproblem represents scheduling requests starting after a given time. - recursion (noun)
- A technique where a solution is built from solutions to smaller versions of the same problem.
The recursion tries every request as the possible first pick. - decision problem (noun)
- A problem whose answer is simply yes or no.
The decision problem asks whether K requests can all be scheduled. - generalization (noun)
- Extending a problem or idea to cover more cases.
A generalization to multiple machines makes the problem much harder. - intractable (adjective)
- So hard to solve that no fast general method is known.
Some scheduling variants become intractable once machines differ. - Hamiltonian cycle (noun)
- A path through a graph that visits every point exactly once and returns to the start.
Checking a Hamiltonian cycle is used as an example of an NP problem. - logistics (noun)
- The practical details of how a course or event is organized.
The lecture opens with a short section on course logistics. - prerequisite (noun)
- Something that must be completed or known before starting something else.
An earlier algorithms course is listed as a prerequisite. - coursework (noun)
- The assignments and work required for a class.
Coursework is submitted through the class website. - resource (scheduling) (noun)
- Something limited, like a machine or room, that requests compete to use.
All requests compete for the same single resource. - boundary (noun)
- The line or point where one thing ends and another begins.
Sharing a boundary point still counts as compatible in this problem. - inductive hypothesis (noun)
- The assumption in a proof that a claim is already true for a smaller case.
The proof applies the inductive hypothesis to the smaller remaining problem. - approximation algorithm (noun)
- A method that finds a solution close to the best one when the best is too hard to compute exactly.
Approximation algorithms are previewed for later intractable problems. - fallback (noun)
- A backup plan used when the preferred method doesn't work.
Exponential-time fallbacks are mentioned for very hard problems.
From the YouTube description
MIT 6.046J Design and Analysis of Algorithms, Spring 2015
View the complete course: http://ocw.mit.edu/6-046JS15
Instructor: Srinivas Devadas
In this lecture, Professor Devadas gives an overview of the course and introduces an algorithm for optimal interval scheduling.
License: Creative Commons BY-NC-SA
More information at http://ocw.mit.edu/terms
More courses at http://ocw.mit.edu
