You are on page 1of 1

AlgorithmDijkstra(L[1..n, 1..n]) : array D[2..

n])
//L is distance between two nodes
//D is the cost array
//C is our nodes
Step 1) array D[2..n]
Step 2) set C
Step 3) C <- {2, 3, 4, 5, 6, …, n}
Step 4) for i <- 2 to n
Step 5) D[i] <- L[1,i]
Step 6) repeat n - 2 times
Step 7) v <- C // minimum D[v] extract to C
Step 8) v <- C - {v}
Step 9) for each w in C do
Step 10) D[w] <- min(D[w], D[v] + L[v,w])
Step 11) return D
1) AlgorithmKruskal(G = (N, A): graph; length: A → R+): set of edges
2) Define an elementary cluster C(v) ← {v}.
3) Initialize a priority queue Q to contain all edges in G, using the weigh
ts as keys.
4) Define a forest T ← Ø //T will ultimately contain the edges of the MST
5) // n is total number of vertices
6) while T has fewer than n-1 edges do
7) // edge u,v is the minimum weighted route from u to v
8) (u,v) ← Q.removeMin()
9) // prevent cycles in T. add u,v only if T does not already conta
in a path between u and v.
10) // the vertices has been added to the tree.
11) Let C(v) be the cluster containing v, and let C(u) be the cluste
r containing u.
13) if C(v) ≠ C(u) then
14) Add edge (v,u) to T.
15) Merge C(v) and C(u) into one cluster, that is, union C(v) and C(
u).
16) return tree T

You might also like