1. Home
  2. Explore
  3. Computer Science
  4. Dynamic Graph Algorithms

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Dynamic Graph Algorithms

Speaker 1Speaker 2

Dynamic Graph Algorithms

11:53
0:00-11:53
  1. Anna

    Welcome back. Today we’re unpacking dynamic graph algorithms: algorithms that keep working as a graph changes, instead of solving the problem once and starting over after every change.

  2. Michael

    The key setup is that we begin with a graph, call it G zero, and preprocess it. Then updates and queries arrive online, one at a time. An update might insert or delete an edge—or sometimes a vertex—and the algorithm must maintain its data structure or answer the new query.

  3. Anna

    So after the first update we call the graph G one, after the second G two, and so on. And there are different tasks we might maintain: whether the whole graph is connected, distances between two vertices, or a larger object such as a minimum spanning tree.

  4. Michael

    It’s useful to distinguish preprocessing time from update time. Preprocessing is the initial work on G zero; update time measures the work at each later step. A worst-case bound says every single step takes at most a certain amount. An amortized bound instead says the total work over k steps is at most k times the claimed average—without averaging over any random distribution.

  5. Anna

    And the update model matters too. Fully dynamic algorithms handle both insertions and deletions. Incremental algorithms handle insertions only, while decremental algorithms handle deletions only.

  6. Michael

    The first general technique is rebuilding. We’ll see it on dynamic matching. A matching is a set of edges that don’t share vertices, and a maximum matching is one with the largest possible number of edges. Let mu of G denote that maximum size; the goal is to keep an approximation to it as the graph changes.

  7. Anna

    The simplest approach is to recompute an approximate matching from scratch after every update. If a static algorithm takes about m over epsilon time on a graph with m edges, that may be expensive. Rebuilding reduces how often we pay that cost.

  8. Michael

    Here’s the basic plan. Compute an approximate matching once, store its size as mu tilde, and then keep returning that value for a while rather than recomputing after every update. After about epsilon times mu tilde updates, rebuild and start another phase.

  9. Anna

    Why can we safely wait? A single edge insertion can increase the maximum matching size by at most one, and a single deletion can decrease it by at most one. So across epsilon times mu tilde updates, the true maximum can drift by at most about epsilon times mu tilde.

  10. Michael

    Right. Immediately after rebuilding, mu tilde approximates the current maximum. During the waiting period, the maximum changes by only a small amount relative to mu tilde, so the stored answer remains an approximation. The exact approximation constants can be handled by choosing the rebuild interval appropriately.

  11. Anna

    Now the cost. A rebuild costs roughly m over epsilon, and we spread that cost over roughly epsilon times mu tilde updates. That gives an amortized cost on the order of m divided by epsilon squared times mu tilde, plus the small per-update work.

  12. Michael

    The useful graph fact is that m is at most about two n times mu of G. Take a maximum matching. Every edge in the graph must touch one of its matched edges; otherwise, an edge joining two unmatched vertices could be added to the matching, contradicting maximal size.

  13. Anna

    For each matched edge, its two endpoints together are incident to at most about two n edges. Summing that bound over the mu matched edges gives m at most 2n mu. Substituting that into the rebuild cost gives an amortized update time on the order of n over epsilon squared—so for fixed epsilon, linear in n.

  14. Michael

    There’s a general lesson here. If an algorithm can handle a phase of L updates, takes rebuild time T-b, and spends at most T-u per update while running, then rebuilding at phase boundaries gives amortized update time about T-b over L plus T-u.

  15. Anna

    But a rebuild creates a big spike: one update might pay the entire rebuilding cost. The next technique, rebuilding in the background, spreads that work across many updates to get a worst-case guarantee.

  16. Michael

    Imagine a phase of length L split into three periods. During the first quarter, start constructing a fresh data structure for the graph as it was at the beginning of the phase. Instead of doing all T-b work at once, do about four T-b over L work on each update.

  17. Anna

    That fresh structure is initially behind, because updates keep arriving while it is being built. During the next quarter—the catch-up period—feed it two past updates for every new update that arrives. It processes updates faster than they arrive and catches up.

  18. Michael

    Once it has caught up, use the structure normally for the final half of the phase. It then gives correct answers during that green, active portion. The work per update is now bounded by about T-b over L plus T-u, rather than having a single large rebuilding spike.

  19. Anna

    One structure alone is only correct for half of each phase. The fix is to maintain two copies and shift their schedules, so that whenever one is building or catching up, the other is in its correct-answer period. That costs only a constant-factor increase in update work, and preprocessing at the very beginning is outside the update bound.

  20. Michael

    So the rebuilding template turns a phase-based algorithm into one that handles an arbitrarily long update sequence with worst-case update time on the order of T-b over L plus T-u. The matching example can use this idea too.

  21. Anna

    The second template is batching. Instead of designing a fully dynamic algorithm immediately, first solve a version where the updates arrive as one batch. The example is decremental connectivity: start with a graph and delete edges, and keep checking whether the whole graph remains connected.

  22. Michael

    A straightforward dynamic method could run a graph search from scratch after every deletion. The lecture instead builds a one-batch algorithm: given one set D of d deleted edges, decide whether the graph after all those deletions is connected.

  23. Anna

    Start by computing a spanning tree of the original graph. Deleting some of its tree edges splits that tree into components. There are at most d plus one such components, because deleting d edges from a tree creates at most d plus one pieces.

  24. Michael

    The graph after deletion is connected exactly when the remaining edges can reconnect those tree components. The deleted non-tree edges are gone too, so the challenge is to find surviving non-tree edges that cross between components.

  25. Anna

    Two data-structure ideas help. An Euler tour represents a tree as a sequence: walk around the tree and record the vertices encountered. Each tree edge appears twice in that tour. The other idea is a two-dimensional range-query structure, which can insert and delete points and report a point inside a specified rectangle.

  26. Michael

    Represent each surviving non-tree edge by a point in two dimensions, using positions associated with its endpoints in the Euler-tour sequence. When a non-tree edge is deleted, delete its point. When tree edges are deleted, the tour is cut into intervals corresponding to the resulting tree components.

  27. Anna

    Those intervals let us form rectangles for pairs of components. Querying the relevant rectangles tells us whether a surviving non-tree edge joins the components. If we find enough connections to keep the pieces connected, the graph remains connected; if not, it doesn’t.

  28. Michael

    There are only on the order of d intervals, so the simple approach makes about d squared rectangle queries. With the stated range-query operations, the one-batch algorithm has near-linear initialization and roughly d squared update-batch work, ignoring polylogarithmic data-structure factors.

  29. Anna

    How does one batch become a dynamic algorithm? For the i-th update in a sequence, form a batch containing all deletions seen so far, and give that prefix batch to the one-batch algorithm. If the prefix has size i, this costs about i squared, so an algorithm handling a phase of L updates has per-step work at most about L squared.

  30. Michael

    Now combine that with background rebuilding. The rebuild or initialization cost is about m, and the within-phase update cost is about L squared. The worst-case bound becomes about m over L plus L squared. Choosing L around m to the one-third balances the two terms and gives an update time around m to the two-thirds.

  31. Anna

    That’s a simple illustrative bound, not the best known result. The important pattern is the reduction: a useful batch algorithm can be converted into a dynamic one, and the batch size becomes a parameter you balance against rebuilding cost.

  32. Michael

    The lecture also posed a two-batch version as an exercise. If an algorithm can process a first batch of size d one and then a second batch of size d two, with costs that depend on the respective batch sizes, suitable choices such as m to the two-thirds and m to the one-third can lead to an m to the one-third update bound through the same kind of scheduling and balancing.

  33. Anna

    More generally, k-batch algorithms can use a sequence of decreasing batch sizes. The speaker noted that some algorithms in the literature handle multiple batches, though the one-batch connectivity idea shown here does not directly explain how to handle a second batch. The point is to recognize batching as a reusable design strategy.

  34. Michael

    The third topic begins with vertex sparsifiers, also called mimicking networks. Start with a large graph and a small set of terminals. The goal is to build a much smaller graph that contains those terminals while preserving useful information about the original graph as seen from the terminals.

  35. Anna

    For example, the lecture mentioned a shortest-path sparsifier: for a parameter k, one can construct a graph with about the number of terminals times n to the one-over-k edges, while terminal-to-terminal distances are preserved within a factor of k. So the smaller graph compresses the original while retaining an approximate answer to a specific kind of question.

  36. Michael

    Then the lecture introduced a different quantity, the minmax path value. For two vertices s and t, look at every path between them, take the largest edge weight on each path, and choose the path whose largest edge weight is smallest. That smallest possible maximum is the minmax value.

  37. Anna

    A minimum spanning tree preserves this information. In the example, the tree path from s to t has maximum edge weight seven, while another route has a largest edge of nine, so the tree path is the better minmax path.

  38. Michael

    The reason is an exchange argument. Suppose the unique path between s and t in a minimum spanning tree were not minmax-optimal. Then there would be another s-to-t path whose edges are all lighter than the heaviest edge on the tree path.

  39. Anna

    Remove that heaviest tree edge, which splits the tree into two parts. The alternative path must cross between those parts, so it contains an edge that can reconnect them. That crossing edge is lighter than the removed edge, giving a spanning tree of smaller total weight—a contradiction.

  40. Michael

    So the minimum spanning tree’s path is minmax-optimal for every pair of vertices. The lecture ends just as it is about to use that fact to construct a vertex sparsifier for minmax paths, so we’ve covered the concepts and proof presented so far without assuming the construction that comes next.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent