|
28 | 28 | (function (exports) { |
29 | 29 | 'use strict'; |
30 | 30 |
|
31 | | - /** |
32 | | - * Initialization.<br><br> |
33 | | - * Time complexity: O(N). |
34 | | - * |
35 | | - * @public |
36 | | - * @constructor |
37 | | - * @param {Numner} size Count of the nodes. |
38 | | - */ |
| 31 | + /** |
| 32 | + * Initialization.<br><br> |
| 33 | + * Time complexity: O(N). |
| 34 | + * |
| 35 | + * @public |
| 36 | + * @constructor |
| 37 | + * @param {Numner} size Count of the nodes. |
| 38 | + */ |
39 | 39 | exports.QuickUnion = function (n) { |
40 | 40 | this._ids = []; |
41 | 41 | this._size = []; |
|
45 | 45 | } |
46 | 46 | }; |
47 | 47 |
|
48 | | - /** |
49 | | - * Finds the root of given node.<br><br> |
50 | | - * Time complexity: O(log N). |
51 | | - * @private |
52 | | - * @param {Number} i The given node. |
53 | | - * @return {Number} Root of the given node. |
54 | | - */ |
| 48 | + /** |
| 49 | + * Finds the root of given node.<br><br> |
| 50 | + * Time complexity: O(log N). |
| 51 | + * @private |
| 52 | + * @param {Number} i The given node. |
| 53 | + * @return {Number} Root of the given node. |
| 54 | + */ |
55 | 55 | exports.QuickUnion.prototype._root = function (i) { |
56 | 56 | while (i !== this._ids[i]) { |
57 | | - // this._ids[i] = this._ids[this._ids[i]]; //enables the path compression |
| 57 | + // this._ids[i] = this._ids[this._ids[i]]; //enables the path compression |
58 | 58 | i = this._ids[i]; |
59 | 59 | } |
60 | 60 | return i; |
61 | 61 | }; |
62 | 62 |
|
63 | | - /** |
64 | | - * Checks whether two nodes are connected.<br><br> |
65 | | - * Time complexity: O(log N). |
66 | | - * |
67 | | - * @param {Number} p The first node. |
68 | | - * @param {Number} q The second node. |
69 | | - * @return {Boolean} True/false depending on whether the nodes are connected. |
70 | | - */ |
| 63 | + /** |
| 64 | + * Checks whether two nodes are connected.<br><br> |
| 65 | + * Time complexity: O(log N). |
| 66 | + * |
| 67 | + * @param {Number} p The first node. |
| 68 | + * @param {Number} q The second node. |
| 69 | + * @return {Boolean} True/false depending on whether the nodes are connected. |
| 70 | + */ |
71 | 71 | exports.QuickUnion.prototype.connected = function (p, q) { |
72 | 72 | return this._root(p) === this._root(q); |
73 | 73 | }; |
74 | 74 |
|
75 | | - /** |
76 | | - * Connects two nodes - p and q.<br><br> |
77 | | - * Time complexity: O(log N). |
78 | | - * |
79 | | - * @public |
80 | | - * @method |
81 | | - * @param {Number} p The first node. |
82 | | - * @param {Number} q The second node. |
83 | | - */ |
| 75 | + /** |
| 76 | + * Connects two nodes - p and q.<br><br> |
| 77 | + * Time complexity: O(log N). |
| 78 | + * |
| 79 | + * @public |
| 80 | + * @method |
| 81 | + * @param {Number} p The first node. |
| 82 | + * @param {Number} q The second node. |
| 83 | + */ |
84 | 84 | exports.QuickUnion.prototype.union = function (p, q) { |
85 | 85 | var pf = this._root(p); |
86 | 86 | var qf = this._root(q); |
|
0 commit comments