Can You Find Bridges in an Undirected Graph Using Only One Array?
Short Answer:
No, you cannot use only a single array of size (O(|V|)) to implement the standard linear-time bridge-finding algorithm (such as Tarjan's algorithm) without losing correctness or efficiency. Both the discovery time (dfn or disc) and the lowest reachable ancestor (low) must be tracked independently for each vertex during DFS traversal.
Why Two Arrays Are Needed
The standard algorithm for finding bridges in an undirected graph (Tarjan's algorithm) relies on two key concepts for each vertex (v):
- Discovery Time (
dfn or disc): The time (DFS order) when the vertex is first visited.
- Low Value (
low): The lowest discovery time reachable from (v) or its descendants, including via back edges (but not via the parent edge).
During DFS, the bridge condition for an edge ((u, v)) (where (u) is the parent of (v)) is:
[
\text{if } \text{low}[v] > \text{disc}[u], \text{ then } (u, v) \text{ is a bridge}
]
This requires both arrays to be maintained separately, because:
disc[v] is fixed at the time of first visit.
low[v] is updated dynamically as DFS explores descendants and back edges.
Merging these two arrays into one would result in loss of information:
If you overwrite disc with low or vice versa, you lose the original discovery time or the updated low value, both of which are needed for the bridge condition check[1][2][3][4][7].
Attempts to Use One Array
Some attempts to use only one array involve recomputing one value from the other or storing both values in a single integer (e.g., using bit-packing), but:
- Recomputing is not possible in linear time: Once the DFS moves past a vertex, you cannot reconstruct its discovery time from the low values alone.
- Bit-packing or tuples: This is still conceptually two arrays, just stored together.
Supporting Explanations
- GeeksforGeeks and CP-Algorithms both show that the standard approach uses two arrays, and their logic depends on having both values available at each step[1][2].
- Stack Overflow explanations and code samples also maintain two arrays (
pre and low), and the bridge condition explicitly compares them[3].
- Wikipedia and other theoretical sources confirm that the algorithm's correctness depends on tracking both values independently[7].
Table: Why Both Arrays Are Needed
| Value | When Set | How Used | Can It Be Overwritten? |
|---|
disc[v] | On first visit | To compare with low of child | No |
low[v] | During/after DFS | To propagate back-edge info | No |
Conclusion
You cannot use only one array of size (O(|V|)) to find bridges in an undirected graph using the standard algorithm. Both dfn (discovery time) and low (lowest reachable ancestor) must be tracked independently to ensure correctness and linear time complexity.[1][2][3][4][7]