Exercise Sheet 10
Exercise Sheet 10
Exercise 1:
a
BFS: 7 4 6 9 10 1 2 3 8 5
Search tree:
b
DFS: 7 4 1 2 3 8 5 6 9 10
Search tree:
Exercise 2:
Iteration D 1 D 2 D 3 D 4 D 5 D 6 u
0 0 ∞ ∞ ∞ ∞ ∞ 1
1 0 1 ∞ ∞ ∞ ∞ 2
2 0 1 ∞ 1 ∞ ∞ 4
3 0 1 2 1 ∞ ∞ 3
4 0 1 2 1 2 ∞ 5
5 0 1 2 1 2 3 6
Exercise 3:
function topologicalSort graph :
visited // Dictionary to keep track of visited nodes
ordering // List to store the topological ordering
return reverse ordering // Return the reversed ordering to obtain the correct topological sorting