Originally published on LeetCopilot Blog


DSU feels abstract until you sketch parent pointers. Here’s how to visualize path compression on grid problems.

Disjoint set union (DSU) feels abstract until you sketch parent pointers. This tutorial shows how to visualize path compression on grid island problems so you can explain every pointer hop in interviews.

TL;DR

  • Union-find tracks connected components with parent pointers; path compression flattens chains to speed up future finds.
  • Interviewers care because island problems hinge on efficient connectivity checks, and explaining pointer rewiring shows mastery.
  • Core steps: map grid cells to ids, initialize each parent to itself, union …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help