can we perform graph lookup( A and B is connected or not?) and connect( connect A and B) in log time using a single array?
I learned some algo like:
quick find (linear time in connect and constant time in lookup) – single array
quick union(constant time connect and average n/2 in lookup) – single array
weighted union(log time in lookup and constant connect time) but this algorithm requires 2 array, one for nodes and another for number of nodes connected for each node.
I am asking just for curiosity. Is it possible to get weighted union sort of complexity using a single array?
You can use Disjoint-Set. It works as a forest, but you can always use an array to implement this forest, with an array of
roots, instead of therootfield per node.The armotized complexity of this implementation is sub-logarithmic, and is often labled as
O(log*(n))