awesome-everything RU
↑ Back to the climb

Algorithms from zero

Graphs: multiple-choice review

Crux Multiple-choice synthesis across the graphs unit: representation tradeoffs, BFS vs DFS, topological sort, Dijkstra's settle invariant, and union-find.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that cut across the whole unit. Each one picks the algorithm or representation a problem actually demands — not a definition to recite, but a modeling decision to defend.

Goal

Confirm you can connect representation choice, traversal order, ordering, weighted shortest paths, and dynamic connectivity — the synthesis the eight lessons built toward.

Quiz

A social graph has 50 million users and ~200 friendships each (so E is roughly 5 billion directed entries, far below V squared). The hot operation is 'iterate a user's friends'. Which representation, and why?

Quiz

You must find the route between two map locations with the fewest road segments, ignoring distance. You only need hop count. Which algorithm is the right first reach, and what makes it correct?

Quiz

A build system runs Kahn's algorithm over its dependency DAG and the output order lists only 18 of the 20 build targets. What does that tell you?

Quiz

A pricing graph has some edges that represent refunds (negative cost). An engineer runs Dijkstra and gets answers that are sometimes too high. Why, and what is the fix?

Quiz

Edges arrive one at a time over a stream, and after each edge you must answer 'are u and v in the same component yet?' instantly. Which structure fits, and why is re-running BFS the wrong choice?

Quiz

A teammate claims their union-find is O(1) per operation because they added path compression. What is the precise complexity, and what is missing or overstated?

Recap

The unit’s through-line is one modeling decision tree: pick the representation by density (list for sparse, matrix for dense or O(1) edge lookup); pick the traversal by what you need (BFS for fewest-edge paths and levels, DFS for depth and cycle structure); add weights and BFS yields to Dijkstra — but only with non-negative edges, else Bellman-Ford. Topological sort orders a DAG and detects cycles for free, and union-find answers dynamic connectivity in amortized O(alpha(n)) where re-running BFS would be wasteful. Match the algorithm to the problem’s shape before writing a line of code.

Continue the climb ↑Graphs: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.