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 :
2、= Next + 1 order(j) := next 把 j添加到 LIST,2,2,广度优先搜索动画,5,如果结点 i 和一条可进入的弧关联,LIST,选择一条可进入弧 (i,j),1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,1,标记结点 j pred(j) := i,2,Next := Next + 1 order(j) := next 把 j 添加到 LIST,2,2,5,5,广度优先搜索动画,6,4,如果结点 i 和一条可进入的弧关联,LIST,选择一条可进入弧 (i,j),1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,1,标记结点
3、j pred(j) := i,2,Next := Next + 1 order(j) := next 把 j 添加到LIST,2,2,5,5,3,4,3,广度优先搜索动画,7,4,如果结点 i 和一条可进入的弧关联,LIST,从LIST删除结点i,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,1,2,2,2,5,5,3,4,3,1,广度优先搜索动画,8,4,选择结点 i,LIST,在LIST上的第一个结点变成了结点 i,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,1,2,2,2,5,5,3,4,3,1,2,广度优先搜索动画,9,5,4,如果结点
4、 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,选择一条可进入弧arc (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j添加到 LIST,4,5,4,广度优先搜索动画,10,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,从LIST删除结点 i,4,5,4,2,广度优先搜索动画,11,5,4,选择一个结点,LIS
5、T,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,4,5,4,在LIST上的第一个结点变成了结点 i,5,广度优先搜索动画,12,6,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,4,5,4,5,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,6,6,6,广度优先搜索动画,13,6,5,4,如果结点 i 和一
6、条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,4,5,4,5,6,6,6,从LIST 中删除结点i,5,广度优先搜索动画,14,6,5,4,选择结点 3,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,2,4,5,4,5,6,6,6,结点3不和任何可进入弧关联,5,3,从LIST中删除结点i,3,广度优先搜索动画,15,6,5,4,选择一个结点,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,
7、3,4,3,4,5,4,6,6,6,i : = 4,4,广度优先搜索动画,16,7,6,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,4,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 把 j 添加到 LIST,8,7,8,广度优先搜索动画,17,7,6,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,
8、1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,4,从LIST删除结点i,8,7,8,4,广度优先搜索动画,18,7,6,5,4,选择结点 i,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,i := 6,8,7,8,6,广度优先搜索动画,19,8,7,6,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,选择一条可进入弧 (i,j),标记结点 j p
9、red(j) := i,Next := Next + 1 order(j) := next 添加j 到LIST中,7,8,7,广度优先搜索动画,20,9,8,7,6,5,4,如果结点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,选择一条可进入弧 (i,j),标记结点 j pred(j) := i,Next := Next + 1 order(j) := next 添加j 到LIST中,7,8,7,9,9,9,广度优先搜索动画,21,9,8,7,6,5,4,如果结
10、点 i 和一条可进入的弧关联,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,从LIST删除结点i,7,8,7,9,9,6,9,广度优先搜索动画,22,9,8,7,6,5,4,选择结点 8,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,结点 8 不和任何可进入弧关联;从LIST中删除它,7,8,7,9,9,6,9,8,8,广度优先搜索动画,23,9,8,7,6,5,4,选择结点7,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,结点7 不和可进入弧关联;从LIST中删除它,7,8,7,9,9,6,9,7,7,广度优先搜索动画,24,9,8,7,6,5,4,选择结点 9,LIST,1,2,4,5,3,6,9,7,8,3,1,1,next,2,3,1,2,2,2,5,5,3,4,3,4,5,4,6,6,6,8,7,8,6,结点 9 不和可进入弧关联;从LIST中删除它,7,8,7,9,9,6,9,9,9,广度优先搜索动画,25,结束,