Graphs & Connectivity Medium
Electricity Network (Minimum Spanning Tree)
Connect buildings with the least total wire cost by considering the cheapest candidate first.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(E log E + E α(V))
AverageO(E log E + E α(V))
WorstO(E log E + E α(V))
SpaceO(V + E)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Return the cost of the minimum spanning tree using Kruskal's algorithm and Union-Find.
- Adding an edge that already closes a cycle.
- Comparing stored sizes for non-root vertices.
- Assuming the implementation rejects disconnected graphs; it returns a minimum spanning forest cost.
Algorithm code
JavaElectricity.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1
Visited 0 · Writes 0