Skip to content

Commit 30f4ab8

Browse files
committed
Enabling the path compression of the weight quick union
1 parent 5a195f3 commit 30f4ab8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/graphs/searching/weightquickunion.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function QuickUnion(n) {
2222
* @return {number} The root of the node
2323
*/
2424
QuickUnion.prototype._root = function (i) {
25-
while (i !== this._ids[i]) i = this._ids[i];
25+
while (i !== this._ids[i]) {
26+
// this._ids = this._ids[this._ids[i]]; //enables the path compression
27+
i = this._ids[i];
28+
}
2629
return i;
2730
};
2831

0 commit comments

Comments
 (0)