The document describes graphs and graph algorithms. It defines what a graph is as G = (V, E) with vertices V and edges E. It provides examples of different types of graphs like directed/undirected, weighted/unweighted, bipartite/not bipartite graphs. It also defines graph concepts like paths, cycles, spanning trees, connected/disconnected components. Finally it summarizes algorithms like shortest path (Floyd-Warshall) and traveling salesman problem.
5. G = (V, E)
E = { {u,v} | u,v ∈ V}
a e
c d g
b f
6. G = (V, E)
E = { {u,v} | u,v ∈ V}
a e
c d g
b f
V = { a, b, c, d, e, f, g }
E = { {a,b}, {a,c}, {b,c}, {c,d}, {d,e}, {d,f}, {e,g}, {f,g} }
7. G = (V, E)
E = { {u,v} | u,v ∈ V}
a e
c d g
b f
V = { a, b, c, d, e, f, g }
E = { {a,b}, {a,c}, {b,c}, {c,d}, {d,e}, {d,f}, {e,g}, {f,g} }
8. a b c d e f g
a 0 1 1 0 0 0 0
b 0 0 1 0 0 0 0 a e
c 0 0 0 1 0 0 0
c d g
d 0 0 0 0 1 1 0
e 0 0 0 0 0 0 1 b f
f 0 0 0 0 0 0 1
g 0 0 0 0 0 0 0
9. a b c d e f g
a 0 1 1 0 0 0 0
b 1 0 1 0 0 0 0 a e
c 1 1 0 1 0 0 0
c d g
d 0 0 1 0 1 1 0
e 0 0 0 1 0 0 1 b f
f 0 0 0 1 0 0 1
g 0 0 0 0 1 1 0
10. a b c d e f g
a 0 1 1 0 0 0 0 2 2
b 1 0 1 0 0 0 0 a e
c 1 1 0 1 0 0 0
c d g
d 0 0 1 0 1 1 0
3 3 2
e 0 0 0 1 0 0 1 b f
f 0 0 0 1 0 0 1 2
g 0 0 0 0 1 1 0
2 2 3 3 2 2 2 Degree of a node
11. a b c d e f g
a 0 2 3 0 0 0 0
b 0 0 1 0 0 0 0 a e
3 5 3
c 0 0 0 2 0 0 0 2
2 c d g
d 0 0 0 0 5 4 0
1 4 3
e 0 0 0 0 0 0 3 b f
f 0 0 0 0 0 0 3
g 0 0 0 0 0 0 0
Weighted graphs
24. G = (V, E)
G1 = (V1, E1)
E1 = {{u,v}∈ E | u,v ∈ V1} ⊆ E.
a e
Subgraph c d g Not subgraph
b f
25. Weakly reachable = exists undirected path
a e
c d g
b f
Strongly reachable = exists directed path
26. 9 F
E
6
2
11 D
14 C
9
15
10
A
7 B
ithm
i jkstr a algor
Exa mple: D
http://scg.unibe.ch/download/lectures/ei/01ComputationalThinking.pptx
27. 9 F
E
6
2
11 D
14 C
9
15
10
A
7 B
ithm
i jkstr a algor
Exa mple: D
28. ∞
9 F
∞ E
6
2 ∞
∞
11 D
14 C
9
15
10
0
A
7 B ∞
ithm
i jkstr a algor
Exa mple: D
29. ∞
9 F
14 E
6
2 ∞
9
11 D
14 C
9
15
10
0
A
7 B 7
ithm
i jkstr a algor
Exa mple: D
30. ∞
9 F
14 E
6
2 7 + 15 = 22
9 < 7 + 10
11 D
14 C
9
15
10
0
A
7 B 7
ithm
i jkstr a algor
Exa mple: D
31. ∞
9 F
14 > 9 + 2 E
6
2 22 > 9 + 11
9
11 D
14 C
9
15
10
0
A
7 B 7
ithm
i jkstr a algor
Exa mple: D
32. 20
9 F
11 E
6
2 20
9
11 D
14 C
9
15
10
0
A
7 B 7
ithm
i jkstr a algor
Exa mple: D
33. 20 < 20 + 6
9 F
11 E
6
2 20
9
11 D
14 C
9
15
10
0
A
7 B 7
ithm
i jkstr a algor
Exa mple: D
34. a b c d e f g
a 0 2 3 0 0 0 0
a e b 0 0 1 0 0 0 0
3 5 3
2 c 0 0 0 2 0 0 0
2 c d g
d 0 0 0 0 5 4 0
1 4 3 e 0 0 0 0 0 0 3
b f
f 0 0 0 0 0 0 3
g 0 0 0 0 0 0 0
Warshall
: Floyd
Example
35. a b c d e f g
a 0 2 3 0 0 0 0
a e b 0 0 1 0 0 0 0
3 5 3
2 c 0 0 0 2 0 0 0
2 c d g
d 0 0 0 0 5 4 0
1 4 3 e 0 0 0 0 0 0 3
b f
f 0 0 0 0 0 0 3
g 0 0 0 0 0 0 0
procedure FloydWarshall ()
for k := 1 to n
for i := 1 to n
for j := 1 to n
path[i][j] = min ( path[i][j], path[i][k]+path[k][j] );
Warshall
: Floyd
E xample