@@ -30,13 +30,13 @@ Kruskal(G) // Compute minimum spanning tree for graph G \\B Kruskal(G)
3030 \\Expl}
3131 \\Note{highlight edge + trees for n1, n2?
3232 \\Note}
33- if n1 and n2 are in different trees \\Ref DifferentTrees
33+ if n1 and n2 are in different trees/sets in NodeSets \\Ref DifferentTrees
3434 \\In{
3535 Add e to Selected \\B addSelected
3636 \\Expl{ The counter used to keep track of size(Selected)
3737 can be incremented here.
3838 \\Expl}
39- union(NodeSets, n1, n2) // update NodeSets, combining n1&n2 \\B union
39+ union(n1, n2) // update NodeSets, combining n1&n2 \\B union
4040 \\Expl{ This is a union-find operation that takes the union
4141 of the sets containing n1 and n2, respectively, since
4242 they are now connected by a selected edge.
6868 from the while loop significantly earlier in some cases.
6969 \\Expl}
7070 NodeSets <- set of singleton sets with each node in G \\B initNodeSets
71- \\Expl{ NodeSets is a set of sets of nodes that are connected by
72- selected edges (like a forest but without information about
73- which edges are used to connect the nodes of each tree).
74- Initially there are no selected edges so we have singleton sets.
71+ \\Expl{ NodeSets represents the structure of the forest: which nodes
72+ are connected to each other (but without information about which
73+ edges are used). Each tree is represented as a just set of nodes;
74+ the forest is a set of sets. A "union find" data structure is
75+ used for efficiency. All nodes in the same set/tree return the
76+ same result for the find() function. Initially there are no
77+ selected edges so each set/tree contains a single node and
78+ find() thus returns a different value for each node.
7579 \\Expl}
7680\\Code}
7781
7882\\Code{
7983DifferentTrees
8084 \\Note{highlight find(n1), find(n2)?
8185 \\Note}
82- if find(NodeSets, n1) != find(NodeSets, n2) \\B DifferentTrees
86+ if find(n1) != find(n2) \\B DifferentTrees
8387 \\Expl{ Find is a union-find operation that returns a representative
84- element of a set containing a given element. If the elements
88+ element of a set in NodeSets containing a given element. If the elements
8589 returned for n1 and n2 are not equal, it means they are not
86- in the same set, so they are not connected by selected edges.
90+ in the same set/tree , so they are not connected by selected edges.
8791 \\Expl}
8892\\Code}
8993
0 commit comments