Draw your graph:
q = graph.getNeighbours(start).sortAscending()
mst = [start]
while(!q.empty())
next = q.popFirst()
if(notVisited(next.vertex))
visit(next.vertex)
q.add(graph.getNeighbours(next.vertex))
q.sortAscending()
mst.append(next.vertex)
SHORT EXPLANATION
---------------------
1. Mark all vertices as unvisited.
2. Visit the first vertex.
3. Find all edges of the vertex and add them to a queue
(cost ascending).
4. Dequeue the first element.
- If the destination vertex has been visited, ignore the
edge.
- If it's not been visited, visit it and repeat steps 3 -
4.
5. The visited vertices and edges form the minimum spanning
tree of the graph.