Engrain by ByteRush

DSA.11.03 Mid-level

Pattern 16: Union-find (disjoint set) + Weighted shortest paths (awareness)

Comes up in: DSA

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • find with path compression
  • union by rank/size
  • near-constant amortised time
  • components and cycle detection
  • Dijkstra with a min-heap
  • why it fails with negative weights
  • Bellman-Ford and A* awareness

Words you will know

disjoint set unionpath compressionDijkstra's algorithmweighted graph

What you will practise

  • number-of-provinces (M)
  • redundant-connection (M)
  • accounts-merge (M)
  • network-delay-time (M)

Interview questions this answers

  • When would you use union-find instead of BFS?