1. In the graph shown as an example in the Topological Sort section of the wiki page, what do the numbers in braces mean?
They are arbitrary identifiers.
They indicate the position of the Node in the partial order of Nodes created by the edges.
They indicate the order in which the Nodes should be listed.
They indicate the order in which the nodes are visited during a BFS.
I know the answer is the second option for this. Why so? Can someone explain briefly?
3. Assume that a graph is not a DAG. Which of following statements is true when doing a DFS from a particular starting point?
For some current node, there is an edge from that node to an already visited node.
For some current node, there is an edge from that node to every node that has not yet been visited.
Every node is seen once.
Every node is seen twice.
Why would the answer be the first option if we're going through the graph for the first time? Each node should be visited for the first time.
4. (Image: http://csns.calstatela.edu/download?fileId=4807108)
Which of the following is NOT a topological ordering for the above graph?
6 2 5 7 1 0 4 3
7 6 2 1 5 0 3 4
7 6 2 1 5 0 4 3
6 2 1 5 0 4 7 3
The answer for this is the second option. Why? Is it because 3 does not have a forward move? How exactly are we supposed to move through the graph? We can start anywhere as long as we're going forward, correct?
5. (Image: http://csns.calstatela.edu/download?fileId=4806612)
Assume we perform depth first traversals of the above (undirected) graph starting at node "a". Which of the following are possible DFS visited lists?
I) a b e g h f
II) a b f h g e
III) a b f e h g
IV) a f g h b e
I, II and IV
I and IV
II, III and IV
I, III and IV
I got the answer to this exercise wrong. Can someone explain why certain traversals (listed) are incorrect? Why?
6. What is the strategy of the topological sort algorithm.
In the following:
a descendant of a node is either a sink or a descendant of a sink. In other words, the descendants of a node are all nodes that can be reached from that node.
a reverse DFS is a DFS that is performed by following links backwards, i.e., from a node to its source nodes.
It does a DFS on each node and labels each node with a label that is less than any of its descendants.
It does a DFS on each node and labels each node with a label that is greater than any of its descendants.
It does a reverse DFS on each node and labels each node with a label that is less than any of its descendants.
It does a reverse DFS on each node and labels each node with a label greater is less than any of its descendants.
Got this answer incorrect as well. Would really like an explanation of this problem.
7. What is the strategy of the shortest path algorithm of Graph.shortestPath(String startID, String endID)?
In the answers, a reverse DFS or BFS is a DFS or BFS that follows edges in their reverse direction, i.e., from Node to source rather than from Node to sink.
Use a DFS starting at endID to build a graph of edges from endId to startID. This graph will have only edges that point from a Node to its source(s). Then use that graph to generate a list of edges from StartID to endID
Use a BFS starting at endID to build a graph of edges from endId to startID. This graph will have only edges that point from a Node to its source(s). Then use that graph to generate a list of edges from StartID to endID
Use a reverse DFS starting at endID to build a graph of edges from startId to endID. This graph will have only edges that point from a Node to its sink(s). Then use that graph to generate a list of edges from StartID to endID
Use a reverse BFS starting at endID to build a graph of edges from startId to endID. This graph will have only edges that point from a Node to its sink(s). Then use that graph to generate a list of edges from StartID to endID
I got this exercise wrong and don't know how to approach it. Where can we find sink vertexes?