1、15.082 和 6.855J,深度优先搜索,2,初始化,LIST,取消在N中的所有结点的标记; 标记结点 s,pred(1) = 0 next := 1 order(next) = 1 LIST:= 1,1,1,3,在LIST中选择结点i,LIST,在深度优先搜索中, i 是LIST中的最后结点,1,1,1,1,4,如果结点 i 和一条可进入的弧关联,LIST,选择一条可进入弧 (i,j),1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,标记结点 j pred(j) := i,2,Next := Next + 1 order(j) := next 把 j 添加到 LIS
2、T,2,2,5,选择在LIST上的最后的结点,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,结点 2 被选择,6,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,4,3,4,7,3,选择,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,选
3、择在LIST上的最后结点,4,3,4,2,4,8,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,4,3,4,2,4,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,8,4,4,8,9,3,选择,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,选择在LIST上的最后的结点,4,8,10,3,如果结点 i 不
4、和可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,从LIST中删除i,8,11,3,选择,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,选择在LIST上的最后的结点,8,4,12,5,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,选择一条可进入弧 (i,j
5、),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,5,5,5,13,5,3,选择,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,选择在LIST上的最后的结点,4,5,14,5,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,选择一条可进入
6、弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,6,6,6,6,15,5,3,选择在LIST上的最后的结点,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,选择结点6,6,6,6,6,5,6,16,7,5,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,
7、4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,9,7,9,17,7,5,3,选择在LIST上的最后的结点,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,选择结点 9,9,7,9,6,9,18,8,7,5,3,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6
8、,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,7,8,7,19,8,7,5,3,选择在LIST上的最后的结点,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,
9、9,7,9,6,9,选择结点 7,7,8,7,9,7,20,8,7,5,3,如果结点 i 不和可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,从LIST中删除结点 7,7,8,7,9,7,7,21,8,7,5,3,选择结点 9,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,
10、9,7,9,6,9,但是结点 9 不和可进入的弧关联,7,8,7,9,7,7,9,从LIST中删除结点 9,9,22,8,7,5,3,选择结点 6,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,但是结点 6 不和一条可进入弧关联,7,8,7,9,7,7,9,从LIST中删除结点 6,9,6,6,23,8,7,5,3,选择结点 5,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3
11、,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,但是结点 5 不和可进入弧关联。,7,8,7,9,7,7,9,从LIST中删除结点5,9,6,6,5,5,24,8,7,5,3,选择结点 4,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,但是结点 4 不和一条可进入弧关联.,7,8,7,9,7,7,9,从LIST删除结点 4,9,6,6,5,5,4,4,25,8,7,5,
12、3,选择结点 2,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,但是结点2 不不和可进入弧相邻.,7,8,7,9,7,7,9,从LIST中删除结点 2,9,6,6,5,5,4,4,2,2,26,9,8,7,5,3,选择结点 1,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6
13、,9,7,8,7,9,7,7,9,9,6,6,5,5,4,4,2,2,1,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next把j 添加到 LIST中,3,9,3,27,9,8,7,5,3,选择结点3,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,7,8,7,9,7,7,9,9,6,6,5,5,4,4,2,2,1,但是结点3 不和可进入的弧关联.,
14、3,9,3,1,3,从LIST中删除结点 3,3,28,9,8,7,5,3,选择结点 1,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,7,8,7,9,7,7,9,9,6,6,5,5,4,4,2,2,1,但是结点1 不和可进入的弧关联.,3,9,3,1,3,从LIST中删除结点1,3,1,1,29,9,8,7,5,3,LIST空了,LIST,1,2,4,5,3,6,9,7,8,1,1,next,1,2,1,1,2,2,2,1,2,3,4,2,4,8,4,4,8,4,8,8,4,5,5,5,4,5,6,6,6,6,5,6,9,7,9,6,9,7,8,7,9,7,7,9,9,6,6,5,5,4,4,2,2,1,算法结束!,3,9,3,1,3,3,1,1,30,深度优先搜索树,注意每个推导出的子树有连续标号的结点。,