Skip to content

Commit 37c99e3

Browse files
committed
docs: update docs for mst and union find
1 parent 3de1a41 commit 37c99e3

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ Gradle is used for development.
107107
* Post-order DFS
108108
* Kahn's
109109
* Floyd Warshall
110-
10. Minimum spanning tree (**WIP**)
111-
* Prim's
112-
* Kruskal's
110+
10. [Minimum spanning tree](src/main/java/algorithms/minimumSpanningTree)
111+
* [Prim](src/main/java/algorithms/minimumSpanningTree/prim)
112+
* [Kruskal](src/main/java/algorithms/minimumSpanningTree/kruskal)
113+
* Boruvska (**WIP**)
113114

114115
## Set-up
115116
If you are a CS2040s student, your IDEA configurations should already be compatible with this project structure. So,
233 KB
Loading

docs/assets/images/QuickUnion1.png

124 KB
Loading

docs/assets/images/QuickUnion2.png

117 KB
Loading

src/main/java/dataStructures/disjointSet/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## Background
44

55
A disjoint-set structure also known as a union-find or merge-find set, is a data structure that tracks a set of elements
6-
partitioned into a number of disjoint (non-overlapping) subsets. It is also commonly used to check for connectivity
7-
(e.g. if two objects are 'grouped' together or belong to some component).
6+
partitioned into a number of disjoint (non-overlapping) subsets. It is commonly used to check for connectivity
7+
(e.g. if two objects are 'grouped' together/belong to some component).
88

99
In CS2040s, this is introduced in the context of checking for dynamic connectivity. For instance, Kruskal's algorithm
1010
in graph theory to find minimum spanning tree of a graph utilizes disjoint set to efficiently

src/main/java/dataStructures/disjointSet/weightedUnion/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ The root node of each tree is used as the identity for all elements in the same
99
Note that the trees here are not necessarily binary trees. In fact, more often than not, we will have nodes
1010
with multiple children nodes.
1111

12+
<div align="center">
13+
<img src="../../../../../../docs/assets/images/QuickUnion1.png" width="40%">
14+
LEADS TO ->
15+
<img src="../../../../../../docs/assets/images/QuickUnion2.png" width="40%">
16+
<br>
17+
Credits: CS2040s Lecture Slides
18+
</div>
19+
1220
### Union
1321
Between the two components, decide on the component to represent the combined set as before.
1422
Now, union is simply assigning the root node of one tree to be the child of the root node of another. Hence, its name.
@@ -72,6 +80,15 @@ the traversal of a node up to the root, we re-assign each node's parent to be th
7280
assigning to its grandparent actually suffice and yield the same big-O upper-bound! This allows path compression to be
7381
done in a single pass.). By doing so, we greatly reduce the height of the trees formed.
7482

83+
_Note: Below shows the 2-pass version of path compression, but what's implemented is the 1-pass version of assigning to
84+
grandparents._
85+
86+
<div align="center">
87+
<img src="../../../../../../docs/assets/images/PathCompression.png" width="50%">
88+
<br>
89+
Credits: CS2040s Lecture Slides
90+
</div>
91+
7592
The analysis with compression is a bit trickier here and talks about the inverse-Ackermann function.
7693
Interested readers can find out more [here](https://dl.acm.org/doi/pdf/10.1145/321879.321884).
7794

0 commit comments

Comments
 (0)