AlgoScope

Interval Partitioning

AlgorithmintermediateGreedy

Sort by start; assign each interval to the first room that is free, else open a new room.

Decision · step 2 of 8Intervals and Greedy Choices: Assigning rooms
012345678910abcdef1!1!1!bbbccccdddeeeefff

a is 0-3. No rooms yet, so it opens room 1.

Open in the player →or start at step 2

What you will see

Rooms as rows; each interval drops into the first row where it fits.

How intervals and greedy choices works →

Cost

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Candidates announce their key and state (candidate, chosen, rejected); each step announces the local choice and its consequence.

Reduced motion: Chosen and rejected states crossfade; no travelling emphasis.

Leads to

Topics that need this one first.

Taught by the same lesson

Intervals and Greedy Choices covers these too, in the same run.