Exercises 22.5 - 算法导论.英文第3版
最近看书的同时, 感觉一些练习缺少参考, 所以按部分总结了自己的解答, 也能够强化学习过程.
如有不足或疑问, 欢迎指正.
如有不足或疑问, 欢迎指正.
Exercises 22.5-1
How can the number of strongly connected components of a graph change if a new
edge is added?
可以将每个强连通组件当作一个顶点, 组成强连通图, 图内顶点数量即强连通组件数量.
如果新增加的边在顶点内部(即指向自己), 或者重复已有顶点间的边, 则数量没变化.
如果新增加的边使图形成环, 这样环内顶点组成一个新的强连通组件, 所以数量减少N, N = (环内顶点数量 - 1).
Exercises 22.5-2
Show how the procedure STRONGLY-CONNECTED-COMPONENTS works on the
graph of Figure 22.6. Specifically, show the finishing times computed in line 1 and
the forest produced in line 3. Assume that the loop of lines 5–7 of DFS considers
vertices in alphabetical order and that the adjacency lists are in alphabetical order.
按照字母排序的循环和邻接表, 可得出第一次DFS访问顶点顺序, 如下
(q (s (v (w, w) v) s) (t (x (z, z) x) (y, y) t) q) (r (u, u) r)
finishing time: f(r) 20, f(u) 19, r(q) 16, f(t) 15, f(y) 14,
f(x) 12, f(z) 11, f(s) 7, f(v) 6, f(w) 5.
根据 finishing time 降序排列, 并倒转上图中的边, 第二次DFS访问顶点顺序, 如下
(r, r) * (u, u) * (q (y (t, t) y) q) * (x (z, z) x) * (s (w (v, v) w) s)
每个不相关括号(用*间隔)内的顶点, 代表 line 3 生成的树(即强连通组件)
Exercises 22.5-3
Professor Bacon claims that the algorithm for strongly connected components
would be simpler if it used the original (instead of the transpose) graph in the