Data Structures19 sections · 729 units
Open in Course

Online vs Offline Problems

Query ordering matters

Online problems: queries arrive one at a time; you must answer before seeing the next. Standard Union-Find works. Offline problems: all queries given upfront; you can process in any order. For offline problems with deletions, reverse time:

1.1. Start with final state (all deletions applied)

2.2. Process queries in reverse, turning deletions into unions

3.3. Answer queries in reverse order Example: "Process edge additions and deletions, answer connectivity after each." - Hard online (need special deletion support)

  • Easy offline (reverse order, deletions become additions)

When you see deletion queries, think "can I solve this offline?"