Content deleted Content added
→Pseudocode: Modify the code so it doesn't fall into an infinite loop if the graph G is not connected |
→Pseudocode: make more readable |
||
Line 42:
Designating each vertex or set of connected vertices a "[[connected component (graph theory)|component]]", pseudocode for Borůvka's algorithm is:
'''algorithm''' Borůvka '''is'''
'''input:''' A weighted undirected graph ''G''
'''output:''' ''F''
Initialize a forest ''F'' to
''completed'' = '''false'''
'''while''' not ''completed'' '''do'''
Find the connected components of ''F'' and
Initialize the cheapest edge for each component to "None"
'''for each''' edge ''uv''
'''if''' ''
''// no more trees can be merged -- we are finished''
''completed'
''completed'' = '''false'''
'''for each''' component whose cheapest edge is not "None" '''do'''
Add its cheapest edge to ''E'''
In the conditional clauses, every edge ''uv'' is considered cheaper than "None". The purpose of the ''completed'' variable is to determine whether the forest ''F'' is yet a spanning forest.
|