Redundant Connection
Expert Answer & Key Takeaways
A complete guide to understanding and implementing Union Find.
Redundant Connection
In this problem, a tree (undirected graph with no cycles) was modified by adding one extra edge. Return the edge that can be removed so the resulting graph is a tree.
Examples
Input: edges = [[1,2],[1,3],[2,3]]
Output: [2,3]
Approach 1
Level I: DFS (Incremental Cycles)
Intuition
For each new edge , check if is already reachable from . If yes, this edge forms a cycle and is redundant.
⏱ O(V^2)💾 O(V)
Detailed Dry Run
Edge [1,2]: Added. Edge [1,3]: Added. Edge [2,3]: DFS(2) finds 3 via 1. Redundant!
Approach 2
Level III: Union-Find (Efficiency)
Intuition
Use DSU to process edges. If an edge connects two nodes that already share the same root, that edge is the redundant one.
⏱ O(V \cdot \alpha(V))💾 O(V)
Detailed Dry Run
Edge [1,2]: Union(1,2). Edge [1,3]: Union(1,3). Edge [2,3]: find(2)=3, find(3)=3. Same component. Return [2,3].
Course4All Technical Board
Verified ExpertSenior Software Engineers & Algorithmic Experts
Our DSA content is authored and reviewed by engineers from top tech firms to ensure optimal time and space complexity analysis.
Pattern: 2026 Ready
Updated: Weekly
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.