I&#x27;m partial to<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Disjoint-set_data_structure" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Disjoint-set_data_structure</a><p>It&#x27;s a fairly simple algorithm to implement, but there is some wicked-cool analysis behind how fast it is.<p>It&#x27;s a super good thing to have in your toolbox for any time you want to do any sort of &quot;simultaneous flood-fill everywhere&quot; or &quot;partition everything&quot; task.