Union-Find (Disjoint Set)
Track which nodes belong to the same group and merge groups quickly, used to detect cycles and build networks.
Union-Find (Disjoint Set) Practice Problems
Easy
1 problemsMedium
7 problems- 98medium
Number of Provinces
Count how many groups of directly or indirectly connected cities exist.
- 99medium
Redundant Connection
Find the extra edge that turns a tree of connections into one with a cycle.
- 100medium
Accounts Merge
Merge accounts that share at least one email address into a single account.
- 101medium
Graph Valid Tree
Check whether a given set of edges and nodes forms a valid tree.
- 255medium
Number of Connected Components in an Undirected Graph
Count the number of connected components in an undirected graph.
- 256medium
Satisfiability of Equality Equations
Determine whether a list of equality and inequality equations can all be satisfied.
- 257medium
Smallest String With Swaps
Find the lexicographically smallest string reachable by swapping indices given as pairs.
Hard
1 problemsRelated concepts
| Topic | Description |
|---|---|
| Kruskal's Algorithm | Build the cheapest network connecting all nodes by adding the smallest edges first, skipping any that form a cycle. |
| Prim's Algorithm | Build the cheapest network connecting all nodes by growing a tree one node at a time, always picking the cheapest edge out. |
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Dijkstra's Algorithm | Find the shortest path from a starting node to every other node in a graph where edges have non-negative weights. |
| Bellman-Ford Algorithm | Find the shortest path from a starting node even when some edges have negative weights, and detect negative cycles. |