QuickUnion

sets/weightquickunion. QuickUnion

new QuickUnion(size)

Initialization.

Time complexity: O(N).
Source:
Parameters:
Name Type Description
size Numner Count of the nodes.

Methods

connected(p, q) → {Boolean}

Checks whether two nodes are connected.

Time complexity: O(log N).
Source:
Parameters:
Name Type Description
p Number The first node.
q Number The second node.
Returns:
Type:
Boolean
True/false depending on whether the nodes are connected.

union(p, q)

Connects two nodes - p and q.

Time complexity: O(log N).
Source:
Parameters:
Name Type Description
p Number The first node.
q Number The second node.