Exchange argument 2026-10-18
An exchange argument modifies an optimal feasible solution to include a desired choice while preserving feasibility and not worsening its objective function value. The modification need not strictly improve the optimum; equality suffices.[ref]
Greedy Algorithms. Algorithms by Jeff Erickson; §4.3 General Pattern, printed pp. 164–165: exchange at the first disagreement
For interval scheduling, the exchange replaces the first selected job with an earliest-finishing job. Its safety comes from the finish-time inequality below. Replacing a job with a shorter one has no such guarantee: it might move the occupied interval into the middle of two useful jobs, as the shortest-duration interval scheduling counterexample shows.
Greedy algorithm Created 2026-10-13 Updated 2026-10-18
A greedy algorithm builds a feasible solution by repeatedly committing to a locally preferred next choice. Each commitment is final: the algorithm does not revisit it when later choices become available. In mathematical optimization, the important question is whether those commitments can still attain the best objective function value.
For example, a shared telescope can accept several observation requests with fixed time slots. In interval scheduling, every completed request counts equally, and overlapping requests cannot both be accepted. Choosing the request that finishes earliest leaves the resource available sooner. The example below turns that intuition into a precise rule, then shows why choosing the earliest start or shortest duration can lose jobs.
Greedy algorithms are attractive because a single pass can replace a search through many candidate subsets. However, "locally best" is only a design proposal. A problem-specific greedy-choice property, often established by an exchange argument, must connect the local decision to the actual objective function. The largest-individual-value rule in the 0-1 knapsack problem fails; Dijkstra's algorithm needs its nonnegative-edge assumptions. A rule's success in one optimization task does not justify it in another.
Greedy-choice property 2026-10-18
A greedy-choice property says that some optimal feasible solution contains the locally selected choice. Together with optimal substructure in the remaining instance, it allows repeated commitments. An exchange argument often establishes this property.[ref]
Greedy Algorithms. Algorithms by Jeff Erickson; §4.3 General Pattern, printed pp. 164–165: exchange without worsening an optimum
For interval scheduling, a safe first choice need not belong to every optimal feasible solution. When several optima exist, a commitment may exclude one while retaining another. The useful loop invariant is that the accepted prefix can still be extended to an optimum. Merely keeping the accepted intervals compatible proves feasibility, which is a weaker claim.
Interval scheduling 2026-10-18
Given a finite set of jobs with fixed half-open intervals , where , choose a subset of maximum cardinality. Each job occupies one shared resource throughout its interval. A feasible solution has pairwise disjoint intervals: for distinct selected jobs , either or . Thus a finish and the next start may coincide. Every job has value one; occupied time is not the objective function.[ref]
Lecture 1: Introduction. 6.046J Design and Analysis of Algorithms, Spring 2015; Printed p. 2, Interval Scheduling: fixed requests, one resource, compatibility with endpoint equality, maximum size
Consider these six original jobs, with arbitrary time units:Job can be followed immediately by and . Job conflicts with all three. Starting the resource earlier is therefore not automatically beneficial: one long commitment can displace several shorter requests.
The earliest-finish greedy algorithm uses a sorting algorithm to put jobs in nondecreasing finish time. Scan that order, accepting the first job and then each job whose start is at least the last accepted finish. Break finish-time ties arbitrarily; an empty input returns the empty set. For these jobs, the order and decisions areAfter , job starts before the current finish five and is rejected. Accept ; then reject because six is before seven. Finally accept . The result is , with cardinality four. Leaving idle makes room for more jobs.
By contrast, the earliest-start rule scans . It accepts , skips , accepts , and skips . Its feasible solution contains only two jobs. Here and meet at time six and are compatible; and overlap on .
Earliest finish accepts four jobs; earliest start accepts two
. The same six original intervals appear in both panels. Colored jobs are accepted and gray jobs rejected. A filled start and hollow finish depict a half-open interval; jobs meeting at an endpoint are compatible. Details.There is also an elementary optimality certificate for this example. The four subsets , , and form a partition of a set of the jobs. A feasible solution takes at most one job from each group: overlap, as do , and each other group is a singleton. Hence four is an upper bound, attained by . Checking all subsets gives a unique optimum of size four: .
The earliest-finish theorem states that this greedy algorithm maximizes job count for every finite instance of interval scheduling. For the exchange argument, let be the first job in an optimal feasible solution and an earliest-finishing job. Every later selected job satisfiesReplace by ; compatibility and cardinality survive. The remainder must be optimal among jobs starting at or after , or improving it would improve the whole selection. Mathematical induction on the smaller remaining instance, starting with the empty set, completes the outline.[ref]
Greedy Algorithms. Algorithms by Jeff Erickson; §4.2 Scheduling Classes, Lemma 4.3 and Theorem 4.4, printed pp. 163–164; endpoint equality is allowed by our half-open convention
Why is the algorithm fast? Once sorted, each job is examined once, using only the last accepted finish to decide compatibility. The scan takes time; comparison sorting algorithms give total time complexity for , in Big O notation, assuming constant-cost endpoint comparisons. Already sorted input needs only the scan.[ref]
Lecture 1: Introduction. 6.046J Design and Analysis of Algorithms, Spring 2015; Printed pp. 2–4, earliest-finish rule, compatibility and first-job exchange; scan cost follows by counting one comparison per subsequent request
Weighted interval scheduling 2026-10-18
Weighted interval scheduling assigns each job a reward and maximizes their sum over compatible jobs. Earliest finish can fail for this different objective function; dynamic programming can compare alternatives.[ref]
Lecture 1: Introduction. 6.046J Design and Analysis of Algorithms, Spring 2015; Printed pp. 4–5, Weighted Interval Scheduling and Dynamic Programming
For a separate two-job example, let have reward one and reward ten. Earliest finish accepts and rejects , earning one; the optimum accepts , earning ten. Replacing by preserves job count but loses reward. Thus the interval scheduling exchange argument proves the unit-value theorem only: its preserved quantity must match the intended objective function.
