Fiveable

๐ŸงฉIntro to Algorithms Unit 12 Review

QR code for Intro to Algorithms practice questions

12.2 Interval scheduling problem and solutions

๐ŸงฉIntro to Algorithms
Unit 12 Review

12.2 Interval scheduling problem and solutions

Written by the Fiveable Content Team โ€ข Last updated September 2025
Written by the Fiveable Content Team โ€ข Last updated September 2025
๐ŸงฉIntro to Algorithms
Unit & Topic Study Guides

Interval scheduling is a classic problem in greedy algorithms. It's all about picking the most non-overlapping tasks from a set, maximizing efficiency without conflicts. This problem pops up in real-world scenarios like booking conference rooms or scheduling TV shows.

The main solution uses the Earliest Finish Time (EFT) strategy. It's simple but powerful: sort tasks by end time, then pick compatible ones. This greedy approach is proven optimal and runs in O(n log n) time, making it both effective and efficient.

Interval Scheduling Problem

Problem Definition and Objectives

  • Interval scheduling selects maximum non-overlapping intervals from a given set
  • Intervals represent tasks or activities with specific durations defined by start and end times
  • Maximize compatible intervals scheduled without conflicts
  • Compatible intervals do not overlap in time
  • Applications span resource allocation, job scheduling, and time management
  • Formal representation: Set of intervals I = {I1, I2, ..., In}, where Ii = (si, fi)
    • si denotes start time
    • fi denotes finish time
  • Goal finds subset S โІ I of maximum size with no overlapping intervals

Mathematical Formulation

  • Objective function: Maximize |S|, where S is the selected subset of intervals
  • Constraints: For any two intervals Ii and Ij in S, either fi โ‰ค sj or fj โ‰ค si
  • Decision variables: xi โˆˆ {0, 1} for each interval Ii
    • xi = 1 if interval Ii is selected
    • xi = 0 if interval Ii is not selected
  • Mathematical model: Maximizeโˆ‘i=1nxi\text{Maximize} \sum_{i=1}^n x_i Subjectย to:xi+xjโ‰ค1ย forย allย i,jย whereย iโ‰ jย andย intervalsย Iiย andย Ijย overlap\text{Subject to:} x_i + x_j \leq 1 \text{ for all } i, j \text{ where } i \neq j \text{ and intervals } I_i \text{ and } I_j \text{ overlap} xiโˆˆ{0,1}ย forย allย i=1,2,...,nx_i \in \{0, 1\} \text{ for all } i = 1, 2, ..., n

Example Scenarios

  • Conference room scheduling (multiple meetings with different durations)
  • Television program scheduling (shows with varying lengths and time slots)
  • Aircraft gate assignment (flights with arrival and departure times)
  • Computer processor task scheduling (processes with execution times)

Greedy Algorithms for Scheduling

Common Greedy Strategies

  • Earliest Finish Time (EFT) selects intervals with earliest end time first
  • Earliest Start Time (EST) prioritizes intervals with earliest start time
  • Shortest Interval First (SIF) chooses interval with shortest duration at each step
  • General structure of greedy algorithms for interval scheduling:
    1. Sort intervals based on chosen strategy
    2. Initialize empty solution set
    3. Iteratively add compatible intervals to solution set

Implementation of Earliest Finish Time (EFT) Strategy

  • Sort intervals by finish time in ascending order
  • Initialize empty solution set S
  • For each interval Ii in sorted order:
    • If Ii does not overlap with any interval in S, add Ii to S
  • Return solution set S
  • Pseudocode:
    function EFT_Interval_Scheduling(intervals):
        sort intervals by finish time
        S = {}
        for interval in sorted intervals:
            if interval does not overlap with any interval in S:
                add interval to S
        return S
    

Handling Tie-breaking Scenarios

  • Multiple intervals may have same priority according to chosen greedy strategy
  • Tie-breaking methods:
    • Random selection among tied intervals
    • Secondary sorting criterion (start time for EFT, finish time for EST)
    • Interval index as final tie-breaker
  • Consistent tie-breaking crucial for reproducibility and analysis

Complexity and Optimality of Greedy Solutions

Time and Space Complexity Analysis

  • Time complexity primarily determined by sorting step
  • Comparison-based sorting algorithms yield O(n log n) overall time complexity
    • n represents number of intervals
  • Selection process after sorting has linear time complexity O(n)
  • Total time complexity: O(n log n) + O(n) = O(n log n)
  • Space complexity generally O(n) for storing:
    • Sorted intervals
    • Solution set

Optimality of Earliest Finish Time (EFT) Algorithm

  • EFT greedy algorithm proven optimal for interval scheduling problem
  • Optimality proof shows EFT always produces maximum cardinality set of non-overlapping intervals
  • Exchange argument technique commonly used in optimality proof:
    1. Assume optimal solution O exists different from EFT solution E
    2. Show E can be transformed into O without reducing number of intervals
    3. Conclude E must be optimal since it cannot be improved

Suboptimality of Other Greedy Strategies

  • Earliest Start Time (EST) may produce suboptimal solutions
    • Example: EST might choose long interval starting early, blocking multiple short intervals
  • Shortest Interval First (SIF) can lead to suboptimal results
    • Example: SIF might select many short intervals, missing longer, non-overlapping intervals that could increase total scheduled time

Greedy Strategies for Interval Scheduling: Earliest Start vs Earliest Finish

Comparison of EFT and EST Strategies

  • EFT consistently produces optimal solutions for interval scheduling
  • EST may yield suboptimal results in certain scenarios
  • EFT allows more efficient time use by prioritizing earlier-ending intervals
    • Potentially accommodates more intervals overall
  • EST preferred when starting tasks early takes precedence over maximizing scheduled intervals
  • Computational complexity similar for both strategies:
    • O(n log n) time for sorting
    • O(n) time for selection

Scenario-based Strategy Selection

  • EFT optimal for maximizing number of scheduled intervals
    • Best for general scheduling problems without additional constraints
  • EST useful in time-critical applications
    • Example: Emergency response tasks where starting early crucial
  • SIF effective for minimizing idle time between tasks
    • Example: Assembly line operations with quick changeovers
  • Hybrid approaches combining multiple strategies possible for complex scheduling problems
    • Example: Prioritize early start for high-priority tasks, then use EFT for remaining slots