AlgoMaster Logo

Number of Connected Components

n=5,edges=[[0,1],[1,2],[3,4]]
0 / 16
Input Graph01234Union-Find Structure0root1root2root3root4rootComponents: 5Legend:StandardProcessingActiveRoot
algomaster.io
Step:Initialize Union-Find for 5 nodes (0 to 4). Each node starts as its own component. Components = 5