Abstract

Suppose you have a conference to plan with events and an unlimited supply of rooms. How can you assign events to rooms in such a way as to minimize the number of rooms used?

  • Category: Greedy / Interval Scheduling variant
  • Input: Start and end times of events
  • Output: An assignment of each event to a room
  • Paradigm: Greedy
  • Typical use cases: room-booking systems, any “schedule onto the fewest identical resources” problem (interval graph coloring)

Problem Specification

  • Instance: Start and end times of events.
  • Solution Format: An assignment of each event to a room.
  • Constraints: No two events that overlap are assigned to the same room.
  • Objective: The total number of rooms used.
  • Goal: Minimize the number of rooms.

Candidate Strategies / Approaches

Strategy 1 ✘

  1. Run Event Scheduling to find the max set of non-overlapping events.
  2. Assign these events to room 1.
  3. Repeat until all events are assigned (room 2, room 3, …).

Note

Conceptually, repeatedly maximizing the non-overlapping set per room doesn’t guarantee the fewest total rooms across the whole schedule — locally optimizing one room at a time isn’t the same as globally minimizing room count.

Strategy 2 ✔

  1. Number each room from to .
  2. Sort the events by earliest start time: .
  3. Assign the first event to room 1.
  4. For events , assign each event to the lowest-numbered room available.

Key Idea

The number of rooms needed is exactly the depth of the schedule — the maximum number of events overlapping at any single point in time. Processing events in order of start time and always taking the lowest-numbered free room guarantees the algorithm never opens more rooms than that depth requires.


Pseudocode (Chosen Approach)

Note

Following the same greedy structure described in Strategy 2. (The Proof of Correctness further below, however, is sourced directly from the lecture’s Achieves-the-Bound derivation.)

Algorithm 42 Interval Partitioning

procedure IntervalPartitioning([(s1,f1),,(sn,fn)][(s_1,f_1), \dots, (s_n,f_n)])

Sort events by start time sis_i

rooms=[]rooms = []//each entry stores the end time of the last event assigned to that room

for each event (si,fi)(s_i, f_i) in sorted order do

if there exists a room rr with end time si\leq s_i then

Assign (si,fi)(s_i, f_i) to the lowest-numbered such room rr

Update room rr’s end time to fif_i

else

Open a new room, assign (si,fi)(s_i, f_i) to it, set its end time to fif_i

return room assignment, rooms|rooms|

Variables & Data Structures

NameTypePurpose
roomsArray (or min-heap) of end timesTracks the end time of the most recently assigned event in each open room
(s_i, f_i)EventThe event currently being placed, in sorted start-time order

Helper Functions / Operations Used

  • Sort by start time — one-time pass.
  • Find lowest-numbered available room — check whether any room’s stored end time is ; naively per event (scanning all currently open rooms), or using a min-heap keyed by room end time.

Proof of Correctness / Optimality

We need to show: for every instance , letting be the greedy algorithm’s solution and be any other solution, (minimizing room count).

The Tricky

Part is an arbitrary valid room assignment — we don’t know its structure. Directly comparing room-by-room against it isn’t feasible, so this is proven instead using the Greedy Achieves the Bound technique (see Techniques to Prove Optimality): find a bound that any solution must respect, then show the greedy algorithm reaches it exactly.

Let be a certain time during the conference, and let be the set of all events happening at time (how busy the conference is at that moment). Let be the number of rooms used in an arbitrary valid schedule.

Claim: for all — the total number of rooms must be able to accommodate the conference at every point in time.

Proof idea: for any time , you need at least rooms, since all events in overlap and must each be in a different room.

Setting up the bound: let . Then is a lower bound on the number of rooms needed by any solution — i.e. .

Greedy achieves this bound: let be the number of rooms the greedy strategy uses.

Claim: at some point , .

Proof: let be the start time of the first event scheduled into room . Room was the minimum-numbered room available at that time, which means at time there were already events going on in rooms , plus the new event now in room . So at this point .

Therefore, at some point in time , — greedy achieves the bound exactly.

Conclusion: let be the greedy solution with rooms, and be any schedule with rooms. By the bounding lemma, . By the achieves-the-bound lemma, . Putting the two together:

Thus the greedy solution (Strategy 2: sort by start time, assign to lowest-numbered available room) is optimal.


Time & Space Complexity Analysis

General Case

ComplexityNotes
TimeDominated by sorting; each event’s room lookup adds with a heap-based rooms structure
SpaceOne entry per open room (at most ), plus the sorted event list

Implementation-Dependent Variations

Data Structure ChoiceImpact on TimeNotes
rooms as a min-heap keyed by end time totalPeek the minimum end time in , update in — efficiently finds a free room, though not necessarily the lowest-numbered one without extra bookkeeping
rooms as a plain array, linear scan per event worst caseSimpler to implement “lowest-numbered room” literally, but scanning all open rooms per event is each

Best / Worst / Average Case

  • Best / Worst / Average case: All with a heap-based implementation — sorting must happen regardless of overlap structure, and every event requires one room lookup/update.

Drawbacks / Constraints

  • Preconditions: assumes an unlimited supply of rooms — this problem is about minimizing count, not fitting into a fixed number. If rooms are capped, this becomes a feasibility/rejection problem instead.
  • Not suitable for: variants where rooms have different costs or capacities — this algorithm only minimizes the count of identical rooms, not any weighted notion of cost.
  • Only tells you room count and assignment — it doesn’t optimize for anything else (e.g. balancing how full each room is, minimizing room-switching for attendees).

References / Links