VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.9 of 16 in this module Unrolled Pro

Redundant Connection

A tree had one extra edge added; find the edge that can be removed to make it a tree again (the last such edge in the input). From checking, before adding each edge, whether its endpoints are already connected with a fresh search (O(E · (V + E))), to union-find with path compression and union by rank, where each check is near O(1). Then union-find explained from first principles, the directed version with a node of two parents, detecting a cycle as data arrives, and the ML twin: catching a contradictory merge in a deduplication pipeline.

about 10 min 3 Python examples 2 quick checks

Problem. A graph started as a tree with n nodes (labelled 1 to n), then one extra edge was added. Given the n edges, return an edge that can be removed so the remaining graph is a tree. If several qualify, return the one that appears last in the input.

text
edges = [[1, 2], [1, 3], [2, 3]]                 →   [2, 3]
edges = [[1, 2], [2, 3], [3, 4], [1, 4], [1, 5]] →   [1, 4]

Add the edges one at a time: the first edge whose two endpoints are already connected closes a cycle, and it's the answer (it's the last edge of that cycle in input order). The whole problem is answering "are u and v already connected?" quickly while edges keep arriving. That's what union-find (disjoint set union) is for.

ML context. Union-find is the engine of record deduplication and entity resolution (lesson 11.15): every "these two records are the same" link merges two clusters. A link between records that are already in the same cluster is redundant, and a "these two are different" constraint between records that end up connected is a contradiction worth flagging (Change D). Kruskal's minimum spanning tree, used in single-linkage clustering, runs the same check on edges sorted by weight.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Redundant Connection"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee