The Union-Find Data Structure in Swift
That is, disjoint sets
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.1, and Swift 5.3
Prerequisites
* You will be expected to be aware how to either make a Single View Application in Swift or use a Playground
* It would be useful to have some knowledge of Sets in Swift
* A dictionary is used to store the nodes
Keywords and Terminology
Data Structure: A way of formatting data Disjoint: (of two or more sets) having no elements in common
Union-find data structure: A data structure that sorts a collection of disjoint sets
The Union-Find Data
The background
Disjoint-set data structures play a key role in an efficient version of Kruskal’s algorithm for finding the minimal spanning tree of a graph, and the data structure form the basis of a wide variety of algorithms including cycle detection.
More than that, they are have applications in Data Science and are even commonly used for LeetCode questions.