Weighted quick union algorithm with Swift

Algorithms are pretty awesome. Understanding how they work and being able to analyse their performance (without actually having to test them) is an essential skill for all programmers, whatever their niche. For every mobile app I’ve ever made, there was at least one challenging algorithm I needed to write.

I recently tweeted a link to a repository containing Swift implementations of lots of algorithms aptly named, “the swift algorithm club“. This followed on from a challenge whereby I needed the weighted quick union algorithm to achieve percolation within my application. I had to write a Swift implementation of this, and I’d like to share it with you guys. You can see if on my Github page as a Gist, and below:

 

Leave a comment