Skip to content

Commit

Permalink
docs: update docs for mst and union find
Browse files Browse the repository at this point in the history
  • Loading branch information
4ndrelim committed Apr 12, 2024
1 parent 3de1a41 commit 37c99e3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ Gradle is used for development.
* Post-order DFS
* Kahn's
* Floyd Warshall
10. Minimum spanning tree (**WIP**)
* Prim's
* Kruskal's
10. [Minimum spanning tree](src/main/java/algorithms/minimumSpanningTree)
* [Prim](src/main/java/algorithms/minimumSpanningTree/prim)
* [Kruskal](src/main/java/algorithms/minimumSpanningTree/kruskal)
* Boruvska (**WIP**)

## Set-up
If you are a CS2040s student, your IDEA configurations should already be compatible with this project structure. So,
Expand Down
Binary file added docs/assets/images/PathCompression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/QuickUnion1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/QuickUnion2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/dataStructures/disjointSet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Background

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

In CS2040s, this is introduced in the context of checking for dynamic connectivity. For instance, Kruskal's algorithm
in graph theory to find minimum spanning tree of a graph utilizes disjoint set to efficiently
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/dataStructures/disjointSet/weightedUnion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ The root node of each tree is used as the identity for all elements in the same
Note that the trees here are not necessarily binary trees. In fact, more often than not, we will have nodes
with multiple children nodes.

<div align="center">
<img src="../../../../../../docs/assets/images/QuickUnion1.png" width="40%">
LEADS TO ->
<img src="../../../../../../docs/assets/images/QuickUnion2.png" width="40%">
<br>
Credits: CS2040s Lecture Slides
</div>

### Union
Between the two components, decide on the component to represent the combined set as before.
Now, union is simply assigning the root node of one tree to be the child of the root node of another. Hence, its name.
Expand Down Expand Up @@ -72,6 +80,15 @@ the traversal of a node up to the root, we re-assign each node's parent to be th
assigning to its grandparent actually suffice and yield the same big-O upper-bound! This allows path compression to be
done in a single pass.). By doing so, we greatly reduce the height of the trees formed.

_Note: Below shows the 2-pass version of path compression, but what's implemented is the 1-pass version of assigning to
grandparents._

<div align="center">
<img src="../../../../../../docs/assets/images/PathCompression.png" width="50%">
<br>
Credits: CS2040s Lecture Slides
</div>

The analysis with compression is a bit trickier here and talks about the inverse-Ackermann function.
Interested readers can find out more [here](https://dl.acm.org/doi/pdf/10.1145/321879.321884).

Expand Down

0 comments on commit 37c99e3

Please sign in to comment.