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

Dynamic Graph Algorithms: Core Techniques

1. Dynamic algorithms and graph updates

A dynamic algorithm interacts with an input that changes over time. After each change, it updates its internal data structure or answers a query about the current input.

For a dynamic graph algorithm:

  1. The algorithm receives an initial graph G0G_0G0​ and may preprocess it.

  2. It receives a sequence of updates and queries online, one step at a time.

  3. After the iiith update, the current graph is denoted by GiG_iGi​.

Graph updates commonly insert or delete edges; some problems also allow vertex updates. Tasks include answering whether a graph is connected, reporting the distance between two vertices, or maintaining a graph structure such as a minimum spanning tree.

Update-time measures

  • Worst-case update time: A bound TTT means that every individual step takes at most TTT time.

  • Amortized update time: A bound TTT means that over any kkk steps, the total processing time is at most kTkTkT. It is an average over the sequence of steps, not an average over a probability distribution. Some steps may take much longer than TTT if other steps are sufficiently cheap.

  • Preprocessing time: The time spent processing the initial graph G0G_0G0​. This is accounted for separately from update time.

Fully and partially dynamic algorithms

  • A fully dynamic algorithm supports both edge insertions and edge deletions.

  • A partially dynamic algorithm supports only one type of change:

    • Incremental: insertions only.

    • Decremental: deletions only.


2. Rebuilding: converting a static algorithm into a dynamic one

A general strategy for dynamic problems is rebuilding: periodically recompute a solution from the current input, then use it for a limited number of updates before rebuilding again.

Example: dynamic maximum matching approximation

A matching is a set of edges that share no endpoints. A maximum matching is a matching with the largest possible number of edges. Let μ(G)\mu(G)μ(G) denote the size of a maximum matching in graph GGG.

Suppose a static algorithm can compute a (1+ϵ)(1+\epsilon)(1+ϵ)-approximation to the maximum matching size in time about O(m/ϵ)O(m/\epsilon)O(m/ϵ), where mmm is the number of edges. A simple dynamic algorithm is:

  1. Compute an approximate matching size μ~\widetilde{\mu}μ​ from scratch.

  2. Keep returning that estimate for approximately ϵμ~\epsilon\widetilde{\mu}ϵμ​ updates.

  3. Recompute the estimate and repeat.

A single edge insertion or deletion can change the maximum matching size by at most 111. Therefore, after roughly ϵμ~\epsilon\widetilde{\mu}ϵμ​ updates, the true matching size can have drifted by at most about ϵμ~\epsilon\widetilde{\mu}ϵμ​ from its value at the last rebuild. With suitable constants in the rebuilding interval and approximation guarantee, the stored estimate remains a (1+ϵ)(1+\epsilon)(1+ϵ)-approximation throughout the phase.

Amortized update-time analysis

If a rebuild costs O(m/ϵ)O(m/\epsilon)O(m/ϵ) and the algorithm waits for about ϵμ~\epsilon\widetilde{\mu}ϵμ​ updates before rebuilding, the rebuild cost amortized over a phase is approximately

O(m/ϵϵμ~)=O(mϵ2μ~).O\left(\frac{m/\epsilon}{\epsilon\widetilde{\mu}}\right) = O\left(\frac{m}{\epsilon^2\widetilde{\mu}}\right).O(ϵμ​m/ϵ​)=O(ϵ2μ​m​).

A maximum matching also gives a useful bound on the number of edges. Every edge must touch a vertex matched by a maximum matching; otherwise, that edge could be added to the matching. Since the matching has μ(G)\mu(G)μ(G) edges and therefore 2μ(G)2\mu(G)2μ(G) endpoints, and each vertex is incident to at most n−1n-1n−1 edges,

m≤2nμ(G).m \leq 2n\mu(G).m≤2nμ(G).

Substituting this bound shows that the amortized update time is O(n/ϵ2)O(n/\epsilon^2)O(n/ϵ2), or O(n)O(n)O(n) when ϵ\epsilonϵ is treated as a fixed constant. The per-update work outside rebuilding is negligible in this example.

Rebuilding can turn an expensive static computation into a useful dynamic algorithm when the solution changes gradually relative to the number of updates between rebuilds.

A general rebuilding principle

Suppose an algorithm can process a batch of LLL updates after rebuilding:

  • The rebuild costs tbt_btb​.

  • Each update handled by the algorithm costs at most tut_utu​.

  • The algorithm is valid for the next LLL updates.

Rebuilding after each block of LLL updates gives amortized update time

tbL+tu.\frac{t_b}{L}+t_u.Ltb​​+tu​.

The first term spreads the rebuild cost across the phase; the second is the cost of processing the updates themselves.


3. Background rebuilding: obtaining worst-case update time

Amortized bounds still permit occasional expensive updates. Background rebuilding spreads the rebuild work over time so that no individual update bears the entire cost.

Assume an algorithm has rebuild cost tbt_btb​, supports LLL updates after a rebuild, and has worst-case update time tut_utu​.

Three periods in a phase

A phase of LLL updates can be divided into three periods:

  1. Rebuild period — first L/4L/4L/4 updates

    • Start constructing a data structure for the graph at the beginning of the phase.

    • Spread the tbt_btb​ units of rebuild work evenly across these updates, spending about 4tb/L4t_b/L4tb​/L work per update.

    • The new structure represents an older graph because updates arrive while it is being built.

  2. Catch-up period — next L/4L/4L/4 updates

    • Process the updates that occurred during rebuilding.

    • Process them at twice the ordinary update rate, so the new structure catches up to the current graph by the end of this period.

  3. Active period — final L/2L/2L/2 updates

    • The structure is now current.

    • Process each new update normally and use the structure to provide correct answers.

The new structure is correct during the active portion of the phase, but not necessarily during the rebuild and catch-up portions. Its per-update work is nevertheless bounded by a constant factor of tb/L+tut_b/L+t_utb​/L+tu​.

Making answers correct at every step

Two copies of the background-rebuilding procedure can be run on offset schedules. When one copy is rebuilding or catching up, the other is in a period where it provides correct answers. Thus, at least one copy is valid at every update.

This doubles the number of structures and increases the update-time bound by only a constant factor. The initial preprocessing required for the offset schedule does not count as update time.

Consequently, an algorithm that supports LLL updates after a rebuild can be converted into one with worst-case update time

O(tbL+tu).O\left(\frac{t_b}{L}+t_u\right).O(Ltb​​+tu​).

Applied to the matching example, this changes the amortized update-time guarantee into a worst-case guarantee, up to constant factors.


4. Batching: designing dynamic algorithms from batch algorithms

Batching separates the problem of processing one update at a time from the problem of processing a whole set of updates together. A batch algorithm often admits a simpler design, and it can then be converted into a dynamic algorithm.

Decremental connectivity

In decremental connectivity, a graph undergoes edge deletions only. A basic approach recomputes connectivity from scratch after every deletion, for example by running breadth-first search. This costs O(m)O(m)O(m) per update.

A faster illustrative approach begins with a one-batch algorithm:

  • It receives a graph GGG and one batch DDD of ddd edge deletions.

  • It must determine whether the resulting graph G−DG-DG−D is connected.

  • It does not need to handle any further batch.

The goal is to obtain a one-batch algorithm with near-linear initialization time and roughly quadratic batch-processing time, then use rebuilding to make it handle an ongoing update sequence.

Turning a one-batch algorithm into a dynamic algorithm

For the iiith update in a deletion sequence, form a batch containing all deletions from the start through update iii, and run the one-batch algorithm on that prefix. If processing a batch of size iii takes O(i2)O(i^2)O(i2) time, then the algorithm can handle a phase of LLL updates with:

  • Rebuild or initialization cost O(m)O(m)O(m).

  • Worst-case per-update cost O(L2)O(L^2)O(L2).

Background rebuilding then gives update time

O(mL+L2).O\left(\frac{m}{L}+L^2\right).O(Lm​+L2).

Balancing the two terms with L=m1/3L=m^{1/3}L=m1/3 yields

O(m2/3)O(m^{2/3})O(m2/3)

worst-case update time. This is a demonstration of the reduction rather than the best known bound for dynamic connectivity.

Constructing the one-batch connectivity algorithm

The algorithm uses a spanning tree, an Euler tour, and a two-dimensional range-query structure.

1. Build a spanning tree and its Euler tour

Initially, compute a spanning tree TTT of GGG. An Euler tour representation records the sequence of vertices visited while walking around the tree. Each tree edge is traversed twice, once in each direction.

The tour represents the tree as a sequence of positions. Deleting a tree edge separates the tree into components and divides the tour representation into intervals.

2. Represent non-tree edges as points

Every edge not in the spanning tree is a non-tree edge. Represent each such edge by a point in a two-dimensional coordinate system derived from the positions of its endpoints in the Euler tour.

A two-dimensional range-query structure maintains a set of points and supports:

  • Inserting or deleting a point.

  • Querying an axis-aligned rectangle to determine whether it contains a point.

The structure can be implemented with standard range-searching data structures; the presentation suppresses polylogarithmic factors in its running-time estimates.

3. Process the deletion batch

  • If a deleted edge is a non-tree edge, remove its corresponding point from the range structure.

  • If a deleted edge is a tree edge, the tree is split into components. A batch of ddd deletions creates only O(d)O(d)O(d) relevant component intervals.

  • Test pairs of components for surviving non-tree edges between them by issuing rectangle queries in the two-dimensional structure.

If the components can still be connected through surviving non-tree edges, then the graph remains connected. If some components cannot be reconnected, the graph is disconnected.

There are O(d2)O(d^2)O(d2) pairs of relevant intervals, so the batch-processing time is O(d2)O(d^2)O(d2), apart from range-query overhead. The one-batch algorithm therefore has near-linear initialization time and quadratic dependence on the batch size.

Multi-batch algorithms

A kkk-batch algorithm handles a sequence of kkk batches, rather than just one. The batches may have different sizes, and the time for later batches can depend on their own sizes rather than on the total number of earlier updates.

For example, consider a two-batch algorithm with near-linear initialization, time proportional to the first batch size for the first batch, and time proportional to the second batch size for the second. Choosing a larger first batch of size about m2/3m^{2/3}m2/3 and a smaller second batch of size about m1/3m^{1/3}m1/3 can support a reduction to an O(m1/3)O(m^{1/3})O(m1/3)-scale dynamic update bound under the stated cost assumptions.

The general idea is to use successively smaller batches and schedule them so that later stages do less work. Multi-batch algorithms can therefore improve the balance achieved by a one-batch reduction. Some graph algorithms use this structure; expander-pruning problems are one example. A one-batch algorithm does not automatically generalize to multiple batches, because the data structures created for the first batch may be difficult to update efficiently for later batches.


5. Rewindability and persistence

Some batching reductions repeatedly rerun a data structure from an earlier state. Rewinding means restoring an algorithm’s configuration to a previous point in its execution.

A technique called persistence can often provide access to earlier versions of a data structure, allowing the algorithm to branch from or revisit prior states without losing the ability to use newer versions. The assumption that an algorithm can be rewound is therefore frequently justified by making its data structure persistent. Randomized algorithms may require additional care because restoring the data structure’s state may also require restoring or managing its random choices.


6. Vertex sparsifiers

A vertex sparsifier, also called a mimicking network in some settings, compresses a graph while preserving information about a specified set of vertices.

Given a large graph GGG and a smaller set of terminals SSS, the goal is to construct a smaller graph HHH that:

  • Contains the terminals in SSS.

  • Has size controlled primarily by ∣S∣|S|∣S∣ rather than by the full size of GGG.

  • Preserves useful information about GGG that is relevant to the terminals.

When HHH preserves or approximates graph properties involving terminals, it is a sparsifier of GGG with respect to SSS. This type of compression is also related to kernelization in parameterized complexity and is studied in approximation algorithms.

Example: approximate distance sparsifiers

For a parameter kkk, one can construct a graph HHH with roughly

∣S∣n1/k|S|n^{1/k}∣S∣n1/k

edges that approximately preserves terminal-to-terminal distances. In particular, distances between terminal pairs in HHH can be kept within a factor of about kkk of their distances in GGG.

The sparsifier can thus be much smaller than the original graph while retaining approximate distance information for the chosen terminals.


7. Minimum spanning trees and minmax paths

A minmax path, also called a bottleneck-minimizing path, minimizes the weight of its heaviest edge. For vertices sss and ttt, its objective is to find an sss-to-ttt path PPP minimizing

max⁡e∈Pw(e),\max_{e\in P} w(e),maxe∈P​w(e),

where w(e)w(e)w(e) is the weight of edge eee.

For example, if one route from sss to ttt has maximum edge weight 777 and another has maximum edge weight 999, the first route is the minmax path, even if its total weight is not the smallest.

Minimum spanning trees preserve minmax paths

Let TTT be a minimum spanning tree of a weighted graph. For any vertices sss and ttt, the unique sss-to-ttt path in TTT is a minmax path.

To see why, suppose the tree path contains an edge emax⁡e_{\max}emax​ of maximum weight www. If there were another sss-to-ttt path whose edges all had weight less than www, adding one of its edges across the cut created by removing emax⁡e_{\max}emax​ would form a spanning tree with smaller total weight. That would contradict the assumption that TTT is a minimum spanning tree.

Thus the heaviest edge on the tree path cannot be heavier than the bottleneck of any alternative path. The tree path therefore minimizes the maximum edge weight among all sss-to-ttt paths.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent