Dynamic Connectivity - Quick Find Algorithm (eager approach, too slow)


Find: To find p and q are connected, check p and q have same entry in array. If entries are same then they are connected.
connected(1,2): entries of 1 and 2 are same, so they are connected!
connected (0,1): entries of 0 and 1 are not same, so they are NOT connected!

Union: To union (p,q), change all entries of p to q. eg to connected (7,8) in above array, change all entries of 7th index to 8th index value.
0 8 8 8 8 0 0 8 8 8






Comments