Practice Discrete Math

Algorithms / Sweep Line Lite

Least You Need to Know: Sweep-Line Lite, Event Ordering, and Active Counts

Sweep-line problems turn geometry or scheduling into a sorted stream of events. The main invariant is an active count or active set that changes only at endpoints, so careful event ordering is often the difference between a correct solution and an off-by-one bug.

The least you need to know

Key notation

event = (x, type) something starts or ends at coordinate `x`
active number of currently open intervals or objects
max_active largest overlap seen during the sweep

Tiny worked example

  • For meeting intervals treated as `[start, end)`, process end events before start events at the same time.
  • That way, one meeting ending at `10` frees a room before another starting at `10` needs it.
  • The active count then matches the true room requirement.

Common mistakes

How to recognize this kind of problem

Start practice