Practice Discrete Math

Algorithms / Union Find Connectivity

Least You Need to Know: Union-Find for Connectivity and Cycles

Union-find, also called **disjoint set union (DSU)**, tracks which items currently belong to the same connected component. It is especially useful when edges are added over time and you need fast connectivity or redundant-edge reasoning.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

find(x) representative of the set containing x
union(x, y) merge the sets containing x and y
component a maximal connected piece under the processed edges

مختصر حل شدہ مثال

  • Start with every vertex in its own set.
  • When an edge `(u,v)` arrives, compare `find(u)` and `find(v)`.
  • If the representatives differ, union the two sets.
  • If the representatives are already equal, the new undirected edge closes a cycle inside an existing component.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Z-Function, Prefix Matches, and Pattern Search by Concatenation.

Least You Need to Know: Z-Function, Prefix Matches, and Pattern Search by Concatenation

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں