graph=[
[0, 1, 999, 9, 999],
[1, 0, 5, 7, 3],
[999, 5, 0, 999, 4],
[9, 7, 999, 0, 3],
[999, 1, 999, 9, 999]
]
For I in Range (0,5):
Print Graph[i]
Points =[' A ', ' B ', ' C ', ' D ', ' E ']
Selected =[]
def is_not_selected (i):
If I in selected:
Return False
Else
Return True
edges = []
#1 Find the shortest edge
#2 Add the points of edge into selected set
#3 in the selected set, add the shortest edge with one of the selected set,while the
def get_minium_tree (edges):
K=0
While k<100:
min=1000
Curi =-1
Curj =-1
For I in Range (0,5):
For j in Range (0,5):
if ((I!=j) and (is_not_selected (i) or is_not_selected (j)):
If MIN>GRAPH[I][J]:
Min= Graph[i][j]
Curi =i
Curj = J
if ((Curi = =-1) or (Curj = =-1)):
Break
If Is_not_selected (Curi):
Selected.append (Curi)
If Is_not_selected (CURJ):
Selected.append (CURJ)
Edges.append ([Points[curi], Points[curj]])
K=k+1
Get_minium_tree (edges)
Print edges
Dynamic Programming--minium span Tree