coursera 错题集

来源:互联网 发布:九型人格出生日期算法 编辑:程序博客网 时间:2024/06/06 18:58


Question 2

(seed = 256010)Consider the adjacency-lists representation of a DAG with 8 vertices and 13 edges:    A:  B E     B:  G C     C:  D     D:      E:  B     F:  G B E     G:  H C     H:  D C Here is a graphical representation of the same DAG:    (A)------------>(B)------------>(C)------------>(D)     |              ^^\              ^^              ^      |             / | \             | \             |      |            /  |  \            |  \            |      |           /   |   \           |   \           |      |          /    |    \          |    \          |      |         /     |     \         |     \         |      |        /      |      \        |      \        |      |       /       |       \       |       \       |      |      /        |        \      |        \      |      |     /         |         \     |         \     |      |    /          |          \    |          \    |      |   /           |           \   |           \   |      |  /            |            \  |            \  |      | /             |             \ |             \ |      v/              |              v|              \|     (E)<------------(F)------------>(G)------------>(H)Give the topological order of the vertices that results from the DFS-basedtopological sort algorithm. As usual, perform the first DFS from vertex A.Your answer should be a sequence of 8 uppercase letters
You entered:
Your Answer ScoreExplanationA B G H D C E FIncorrect0.00 Total 0.00 / 1.00 
Question Explanation

The correct answer is: F A E B G H C DHere is a trace of the depth-first search:dfs(A)  dfs(B)    dfs(G)      dfs(H)        dfs(D)        D done        dfs(C)          check D        C done      H done      check C    G done    check C  B done  dfs(E)    check B  E doneA donecheck Bcheck Ccheck Dcheck Edfs(F)  check G  check B  check EF donecheck Gcheck HThe postorder is the order in which the vertices are done. The reverse postorderprovides a topological order.
(seed = 521570)Consider the adjacency-lists representation of a digraph G with 10 vertices and 17 edges:    A:  G     B:  A H     C:  D B H I     D:  I     E:  J D     F:  A     G:  B F     H:  G     I:  H E     J:  I Here is a graphical representation of the same digraph G:    (A)<------------(B)<------------(C)------------>(D)<------------(E)     ^\              ^\              |\              |              ^|      | \             | \             | \             |             / |      |  \            |  \            |  \            |            /  |      |   \           |   \           |   \           |           /   |      |    \          |    \          |    \          |          /    |      |     \         |     \         |     \         |         /     |      |      \        |      \        |      \        |        /      |      |       \       |       \       |       \       |       /       |      |        \      |        \      |        \      |      /        |      |         \     |         \     |         \     |     /         |      |          \    |          \    |          \    |    /          |      |           \   |           \   |           \   |   /           |      |            \  |            \  |            \  |  /            |      |             \ |             \ |             \ | /             |      |              v|              vv              vv/              v     (F)<------------(G)<------------(H)<------------(I)<------------(J)Compute the strongly-connected components of the digraph using the Kosaraju-Sharir algorithm.Assume that the first depth-first search of Kosaraju-Sharir computes the reverse postorder of G^R:    A F G H B I D C J E Give the sequence of the 10 integers in the id[] array for the vertices A through J.       v    A  B  C  D  E  F  G  H  I  J      ------------------------------------    id[v]                                 
You entered:
Your Answer ScoreExplanation0 0 1 1 1 0 0 1 1Incorrect0.00 Total 0.00 / 1.00 
Question Explanation

The correct answer is: 0 0 2 1 1 0 0 0 1 1   v    A  B  C  D  E  F  G  H  I  J  ------------------------------------id[v]   0  0  2  1  1  0  0  0  1  1  The second depth-first search considers the vertices in the following order:    A F G H B I D C J E Here is a trace of the second depth-first search:strong component 0------------------dfs(A)  dfs(G)    dfs(B)      check A      dfs(H)        check G      H done    B done    dfs(F)      check A    F done  G doneA done------------------check Fcheck Gcheck Hcheck Bstrong component 1------------------dfs(I)  check H  dfs(E)    dfs(J)      check I    J done    dfs(D)      check I    D done  E doneI done------------------check Dstrong component 2------------------dfs(C)  check D  check B  check H  check IC done------------------check Jcheck E
0 0
原创粉丝点击