Professional Documents
Culture Documents
Depth First Search: CS122 Algorithms and Data Structures
Depth First Search: CS122 Algorithms and Data Structures
n
n
n
n
n
An Example
Algorithm
n
n
n
n
n
n
Ford Algorithm
FordAlgorithm(G, s)
for all vertices v do
dist[v] = ; p[v] = NULL;
dist[s] = 0;
while there is (v,u) that dist[u]>dist[v] + weight(v,u) do
dist[u] = dist[v] + weight(v,u);
p[u] = v;
endwhile
10
Spanning tree
subgraph of G
contains all vertices of G
n connected graph with no cycles
Kruskal's algorithm
n
4
2
4
8
2
3
10
4
1
13
14
Prim's algorithm
15
4
2
4
8
1
2
4
8
10
2
3
10
4
1
6
17