MA/CSSE 473 – Design and Analysis of Algorithms In

advertisement
MA/CSSE 473 – Design and Analysis of Algorithms
In-class Quiz Day 15
Name:_____________Solution__________ Score:____/ 10
circle your Section # 01(3rd)
02 (4th)
1. If a graph has n vertices and m edges, what is the running time of the DFS algorithm?
Depends on representation of the graph
Adjacency matrix representation: (n2)
Adjacency list representation: (n+m)
2. In DFS, graph nodes are pushed onto the stack in one order and popped off in a different order.
If the graph is a rooted tree (and we start at the root), the "push order" is a __preorder__ traversal of the
tree, and the "pop order" is a ___postorder_____ traversal.
3. For the following undirected graph, do a BFS search (starting at a, and always preferring nodes whose names
come first alphabetically). Show the queue, and indicate which edges in the original graph are “cross edges” for
the spanning tree produced by this traversal
Queue: abefgchd
Cross-edges (in the order they are discovered): bf, ef, dh
4. In BFS, graph nodes are visited in the order in which they are added to the queue..
If the graph is a rooted tree (and we start at the root), this order is a ___level order_____ traversal.
5. What is a dag? A directed acyclic graph. I.e., a directed graph with no cycles.
6. What is a topological sort of a dag?
The vertices are ordered so that for every (directed) edge, its starting vertex comes before its ending
vertex
7. How can we use DFS to produce a topological sort?
Start with the order in which DFS pops the nodes off its stack.
The reverse of that order is a topological sort.
If we ever find an edge to an already-visited node, the graph is not a dag (this is not a required part of the
quiz answer)
8. How can we use "source removal" to produce a topological sort?
A dag must have at least one source vertex. That can be output as the first vertex in the topological sort.
Remove that vertex and any edges that come out of it from the graph. Repeat until all vertices have been
output.
9. How is topological sort useful for a spreadsheet application?
A cell’s formula may make it dependent on other cells’ values, so it cannot be calculated until after those
other cells’ values have been calculated.
10. What became clear to you as a result of today’s discussion? (or write N/A)
Must have an answer
11. Is there anything from today's discussion that was unclear, do you have questions, or is there anything else you
want to tell me? (or write N/A)
Must have an answer
Download