1135. Connecting Cities With Minimum Cost
Kruskal Algorithm:
Union-Find and + sort edge by height, add edge if not connected
time: union-find for each vertex: O(1), total O(E); sort array: ElogE.
total O(ElogE+E)
space: O(V)
Last updated
Kruskal Algorithm:
Union-Find and + sort edge by height, add edge if not connected
time: union-find for each vertex: O(1), total O(E); sort array: ElogE.
total O(ElogE+E)
space: O(V)
Last updated