CS502 Design And Analysis of Algorithms
Spring 2017, HW #6
Due Date/Time:
March 1, 2016 (Wednesday Session)
March 3, 2016 (Friday Session)
================================================
Student ID:
Name:
================================================
Topological Sorting Problem:
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of
vertices such that for every directed edge uv, vertex u comes before v in
the ordering. We can use the DFS algorithm to get the topological order of nodes on
the directed acyclic graph as shown below.
Topological-Sort()
{ // condition: the graph is a DAG
Run DFS
When a vertex, say v, is finished, add v to a list L
Reverse list L and print out each node in list L.
}
Consider the following graph where DFS begins with node A (i.e. its start time is 0).
Find out the discovered and finished time for each node, and the topological order.
Note that the answers can be not unique. To make the answer unique, we assume
that lower-numbered edges are explored first. For example, node C will be explored
before node B.
1. The discovered times for node C is ________.
a) 1
b) 2
c) 3
d) 4
e) 5
2. The finished times for node C is ________.
a) 8
b) 7
c) 6
d) 5
e) 4
3. The discovered times for node E is _________________
a) 4
b) 5
c) 6
d) 7
e) 8
4. The topological order of nodes output by the DFS algorithm is ________
a) the decreasing order of their finished time.
b) the decreasing order of their discovered time.
c) the increasing order of their discovered time.
d) the increasing order of their finished time.
5. The topological order of nodes, in this example, is A, C, _____, _____, ____
a) B,D,E
b) E,B,D
c) E,D,B
d) B,E,D
6. The linear ordering A, B, C, D, E violates the definition of the topological
sorting order that every directed edge (u, v), vertex u comes before v in
the ordering. Which directed edge causes the violation?
a) A -> B
b) A->C
c) A->E
d) C->B
7. Consider the following undirected graph, where node s is the starting node
What graph search algorithm would visit all the nodes in the order of S,W,X,Y,T,R,V?
a) Depth-First Search
b) Breadth-First Search
c) It depends.
8. (Continue) What graph search algorithm would visit all the nodes in the order of
S,W,R,T,X,V,Y?
a) Depth-First Search
b) Breadth-First Search
c) None
9. (Continue) If we do a Breadth-First Search starting with node s, which node will
be the last node to be visited?
a)
b)
c)
d)
e)
V
W
T
X
Y
10. For a graph G(V,E) with |V|=n vertices and |E|=m edges. Kruskal's algorithm
runs in O(m*log n) time, where Prim's algorithm can run in O(m + n*log n)
amortized time by using a Fibonacci Heap. Which of the following is NOT
correct?
a) Prim's run in O(n2) in a dense graph where m= O(n2)
b) Kruskal's run in O(n2log n) in a dense graph where m= O(n2)
c) Kruskal's run and Prim have the same time complexity O(n*log n) in a sparse
graph where m= O(n)
d) Both Kruskal's run and Prim’s have the same time complexity O(n2 * log n)
for a dense graph where m= O(n2)
Prim's Algorithm for the Minimum Spanning Tree.
Use the given Graph and table to answer the questions.
Dv = Cheapest edge cost to connect node v to tree T
pv= Node in T to which the cheapest edge is connected
11. The value of dE is
a) 1 b) 2 c) 3
d) 4
e )5
12. Which of the following is not correct?
a) dF=10
b) pB = A
c) pC = B
d) pD = pF=C
e) Total Cost = dA+dB+dC+dD+dE+dF
13. The value of pF is
a) A b) B c) C d) F
e) D
14. What is the correct order of the nodes that are added to the tree?
a) A,B,C,D,F,E
b) A,B,C,D,E,F
c) A,B,D,C,E,F
d) A,B,D,C,F,E
e) A,B,C,E,D,F
Kruskal's Algorithm for Minimum Spanning Tree
Use the given Graph and table to answer the questions.
15. Which of the following edges is not in the resulting tree?
a) edge (C,D)
b) edge (E,F)
c) edge (F,C)
d) edge (B,C)
e) edge (B,F)
16. If we add a new edge, say (A,E) with edge weight x to the graph.
What value of x will change the cost of the minimum spanning tree?
a) x=7
b) x=8
c) x=9
d) x=10
e) x=11
Dijkstra's Algorithm for Shortest Path Tree
Use the given Graph and table to answer the questions.
Dv = Shortest path length from source node s to v
pv = Node in T to which the cheapest edge is connected
17. Which of the following is NOT true?
a) The shortest path from A to C is 13
b) The shortest path from A to D is 14
c) The shortest path from A to E is 12
d) The shortest path from A to F is 10
e) The cost of the tree is = dA + dB+dC+dD+dE+dF = 55
18. The shortest-path tree T is growing by adding nodes one by one. Which of the
following entry in the table will not change before and after F is added to tree T?
a) dE
b) pE
c) dD
d) pD
e) pC
19. What is the correct sequence of the nodes that are added to the tree?
a) ABFECD
b) ABFEDC
c) ABEFCD
d) ABEFDC
e) ABCDEF
Prim's Algorithm for the Minimum Spanning Tree.
Use the given Graph and table to answer the questions.
Dv = Cheapest edge cost to connect node v to tree T
pv= Node in T to which the cheapest edge is connected
20. In the spanning tree constructed by the Prim’s algorithm, the value of dE is
a) 1
b) 2
c) 3
d) 4
21. In the spanning tree constructed by the Prim’s algorithm, which of the following
is not a correct value in the table?
a) pB =A
b) pC =F
c) pD=C
d) dF=4
22. The value of pF is
a) A b) B c) C d) F e) D
23. What are the first three nodes that are added to the tree?
a) A,B,C
b) A,B,D
c) A,B,E
d) A,B,F
e) A,F,E
Kruskal's Algorithm for Minimum Spanning Tree
Use the given Graph and table to answer the questions.
24. Which of the following edges is not included in the resulting tree?
a) edge (C,D)
b) edge (E,F)
c) edge (B,F)
d) edge (F,C)
25. The Kruskal’s algorithm grow tree T by adding a sequence of edges.
What is the correct sequence of the edges that are added to T.
a) The first edge added to T is (C,D)
b) The second edge added to T is (F,E)
c) The third edge added to T is (F,C)
d) The fourth edge added to T is (A,F)
e) The fifth edge added to T is (B,F)
26. The cost of the spanning tree T by the Kruskal’s algorithm is minimum, and it is
the sum of the edge cost in the T. What is the cost of T?
a) 15
b) 16
c) 17
d) 18
Dijkstra's Algorithm for Shortest Path Tree
Use the given Graph and table to answer the questions.
Dv = Shortest path length from source node s to v
pv = Node in T to which the cheapest edge is connected
27. Which of the following is NOT true?
a) The shortest path from A to C is 7
b) The shortest path from A to D is 8
c) The shortest path from A to B is 8
d) The shortest path from A to E is 18
28. The sum of dA + dB+dC+dD+dE+dF is equal to the sum of cost of each edge in the
resulting shortest path tree T.
a) True
b) False
29. The total edge cost of the shortest path tree T cannot be less than that of the
minimum spanning tree.
a) True
b) False
30. The shortest-path tree T is growing by adding nodes one by one. What is the
correct sequence of the first 3 nodes that are added to the tree?
a) AFE
b) AFC
c) AFD
d) AED
© Copyright 2026 Paperzz