15.082 and 6.855J Depth First Search Get ahold of a network, and use the same network to illustrate the shortest path problem for communication newtorks, the max flow problem, the minimum cost flow problem, and the multicommodity flow problem. This will be a very efficient way of introducing the four problems. (Perhaps under 10 minutes of class time.)
Initialize 1 2 4 5 3 6 9 7 8 1 2 4 5 3 6 9 7 8 1 1 pred(1) = 0 next := 1 order(next) = 1 LIST:= {1} Unmark all nodes in N; Mark node s LIST 1 next 1
Select a node i in LIST 1 2 4 5 3 6 9 7 8 1 1 1 In depth first search, i is the last node in LIST LIST 1 next 1
If node i is incident to an admissible arc… 2 4 2 2 8 1 1 1 1 5 7 Next := Next + 1 order(j) := next add j to LIST Mark Node j pred(j) := i Select an admissible arc (i,j) 9 3 6 LIST 1 2 2 1 next
Select the last node on LIST 2 4 2 2 2 8 1 1 1 1 1 5 7 9 3 6 Node 2 gets selected LIST 1 2 2 1 next
If node i is incident to an admissible arc… 2 4 4 2 2 2 3 8 1 1 1 1 1 5 7 Select an admissible arc (i,j) Next := Next + 1 order(j) := next add j to LIST Mark Node j pred(j) := i 9 3 6 LIST 1 2 4 3 2 1 next
Select 2 4 4 4 2 2 2 2 3 8 1 1 1 1 1 5 7 Select the last node on LIST 9 3 6 LIST 1 2 4 2 3 1 next
If node i is incident to an admissible arc… 2 4 4 4 2 2 2 2 3 8 8 4 1 1 1 1 1 5 7 Mark Node j pred(j) := i Select an admissible arc (i,j) Next := Next + 1 order(j) := next add j to LIST 9 3 6 LIST 1 2 4 8 3 4 2 1 next
Select 2 4 4 4 2 2 2 2 3 8 8 8 4 1 1 1 1 1 5 7 Select the last node on LIST 9 3 6 LIST 1 2 4 8 3 2 1 4 next
If node i is not incident to an admissible arc… 2 4 4 4 2 2 2 2 3 8 8 8 8 4 1 1 1 1 1 5 7 Delete node i from LIST 9 3 6 LIST 1 2 4 8 1 3 2 4 next
Select 2 4 4 4 4 2 2 2 2 3 8 8 8 8 4 1 1 1 1 1 5 7 Select the last node on LIST 9 3 6 LIST 1 2 4 8 1 4 2 3 next
If node i is incident to an admissible arc… 2 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 7 Mark Node j pred(j) := i Next := Next + 1 order(j) := next add j to LIST Select an admissible arc (i,j) 9 3 6 LIST 1 2 4 5 8 1 5 2 4 3 next
Select 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 5 7 Select the last node on LIST 9 3 6 LIST 1 2 4 8 5 1 2 5 3 4 next
If node i is incident to an admissible arc… 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 5 7 Select an admissible arc (i,j) Next := Next + 1 order(j) := next add j to LIST Mark Node j pred(j) := i 9 3 6 6 6 LIST 1 2 4 8 5 6 6 3 4 2 5 1 next
Select the last node on LIST 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 5 5 7 Select node 6 9 3 6 6 6 6 LIST 1 2 4 8 5 6 3 4 6 5 1 2 next
If node i is incident to an admissible arc… 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 5 5 7 Mark Node j pred(j) := i Select an admissible arc (i,j) Next := Next + 1 order(j) := next add j to LIST 9 9 3 6 6 6 7 6 LIST 1 2 4 5 8 6 9 1 7 2 4 5 3 6 next
Select the last node on LIST 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 1 1 1 1 5 5 5 5 7 Select node 9 9 9 9 3 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 1 2 4 6 5 3 next
If node i is incident to an admissible arc… 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 7 7 Select an admissible arc (i,j) Next := Next + 1 order(j) := next add j to LIST Mark Node j pred(j) := i 9 9 9 3 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 8 4 3 1 6 2 5 7 next
Select the last node on LIST 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 7 7 7 Select node 7 9 9 9 9 3 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 4 8 1 6 2 3 5 7 next
If node i is not incident to an admissible arc… 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 7 7 7 7 Delete node 7 from LIST 9 9 9 9 3 6 6 6 6 7 6 LIST 1 2 4 8 5 6 9 7 1 2 8 4 6 3 7 5 next
Select node 9 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 7 7 7 7 Delete node 9 from LIST But node 9 is not incident to an admissible arc. 9 9 9 9 9 9 3 6 6 6 6 7 6 LIST 1 2 4 8 5 6 9 7 8 4 2 1 7 3 5 6 next
Select node 6 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 7 7 7 7 But node 6 is not incident to an admissible arc. Delete node 6 from LIST 9 9 9 9 9 9 3 6 6 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 4 3 2 6 7 8 1 5 next
Select node 5 2 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 5 5 7 7 7 7 But node 5 is not incident to an admissible arc. Delete node 5 from LIST 9 9 9 9 9 9 3 6 6 6 6 6 6 7 6 LIST 1 2 4 8 5 6 9 7 3 2 1 4 5 6 8 7 next
Select node 4 2 4 4 4 4 4 4 4 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 5 5 7 7 7 7 Delete node 4 from LIST But node 4 is not incident to an admissible arc. 9 9 9 9 9 9 3 6 6 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 7 1 2 5 8 4 6 3 next
Select node 2 2 4 4 4 4 4 4 4 2 2 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 5 5 5 5 5 5 7 7 7 7 But node 2 is not incident to an admissible arc. Delete node 2 from LIST 9 9 9 9 9 9 3 6 6 6 6 6 6 7 6 LIST 1 2 4 5 8 6 9 7 6 3 1 4 5 7 2 8 next
Select node 1 2 4 4 4 4 4 4 4 2 2 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 1 5 5 5 5 5 5 7 7 7 7 Next := Next + 1 order(j) := next add j to LIST Mark Node j pred(j) := i Select an admissible arc (i,j) 9 9 9 9 9 9 3 3 6 6 6 6 6 6 7 9 6 LIST 1 3 2 4 8 5 6 9 7 2 6 9 7 3 8 5 1 4 next
Select node 3 2 4 4 4 4 4 4 4 2 2 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 1 1 5 5 5 5 5 5 7 7 7 7 Delete node 3 from LIST But node 3 is not incident to an admissible arc. 9 9 9 9 9 9 3 3 3 3 6 6 6 6 6 6 7 9 6 LIST 1 3 2 4 5 8 6 9 7 9 8 5 3 4 2 1 7 6 next
Select node 1 2 4 4 4 4 4 4 4 2 2 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 1 1 1 1 5 5 5 5 5 5 7 7 7 7 Delete node 1 from LIST But node 1 is not incident to an admissible arc. 9 9 9 9 9 9 3 3 3 3 6 6 6 6 6 6 7 9 6 LIST 1 2 3 4 8 5 6 9 7 9 5 2 1 3 4 7 6 8 next
LIST is empty 2 4 4 4 4 4 4 4 2 2 2 2 2 2 3 8 8 8 8 4 5 1 8 1 1 1 1 1 1 1 1 5 5 5 5 5 5 7 7 7 7 The algorithm ends! 9 9 9 9 9 9 3 3 3 3 6 6 6 6 6 6 7 9 6 LIST 1 2 3 4 5 8 6 9 7 9 4 5 3 6 2 1 7 8 next
The depth first search tree 1 3 2 9 8 7 5 4 6 Note that each induced subtree has consecutively labeled nodes