Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69813d1

Browse files
Update README.md
1 parent 7e67a51 commit 69813d1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

‎README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Kruskal's Algorithm Minimum Spanning Tree (Graph MST)
22

3-
Java Implementation of Kruskal's Algorithm using **disjoing sets**
3+
Java Implementation of Kruskal's Algorithm using **disjoing sets**
4+
**Kruskal's algorithm:** Start with T = ∅. Consider edges in ascending order of weight. Insert edge e into T unless doing so would create a cycle
45

56
##PseudoCode
67
![kruskal-pseudocode](https://cloud.githubusercontent.com/assets/15304528/23335535/450deca2-fb85-11e6-9fd6-ce146ddb3471.png)
@@ -17,9 +18,16 @@ It produces this Minimum Spanning Tree
1718
- Requires **distinct nodes named with consecutive integers**. If they really **do** have the same "name", convert them to integer ID's to use this algorithm
1819
Example graph has 8 nodes numbered 1-8 (array ignores the 0th index)
1920
- **You must hardcode the graph structure in constructor** as a **list of edges**
21+
- `graphEdges` is **indexed from 1** to make it more human-readable. In the constructor:
22+
`graphEdges=new ArrayList<Edge>();` //creates empty ArrayList
23+
`graphEdges.add(new Edge(0, 0, 0));` //adds dummy edge before any actual edges
24+
**The 0th index is ignored because the loop starts @ 1**
25+
- `DisjointSet nodeSet = new DisjointSet(nodeCount+1);` also skips the 0th index by creating a Disjoint Set **1 larger than the number of nodes**
2026
- **Make sure `nodeCount` is accurate**. There's no error checking between `nodeCount` & the actual edge list
27+
- `outputMessage` is a string that records the steps the algorithm takes. It's printed to the screen & to a file once complete
2128
- My implementation has **early termination**. If a graph has **N nodes** the MST has **(N-1) edges**
2229
Hence `&& mstEdges.size()<(nodeCount-1)` in my loop
30+
- The `Edge` class simply packages an edge's weight & 2 vertices together as 1 object
2331

2432
####Sources
2533
- [Disjoint Sets by Mark Allen Weiss](http://users.cis.fiu.edu/~weiss/dsaajava3/code/DisjSets.java) Author of *Data Structures and Algorithm Analysis in Java (3rd Edition), 2011*

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /