Exam 2 Flashcards
Tree edge
edge in DFS graph
DFS output is a tree/forest (T/F)
true
Types of edges not in DFS tree
back, forward, and cross edges: these edges are not in the DFS tree but are in the original graph
post-ordering of edge z->w
post(z) > post(w) except for back edges
How do we know if G has a cycle?
G has a cycle if and only if its DFS tree has a back edge
Post order number
When doing DFS, when we first visit a node, we give it a number (pre-order) and increase our counter, when we leave a node, we give it a number and increase our counter (post order)
How to do topological sorting (2 ways)
- Run DFS on a DAG
- We know that for all z->w, post(z) > post(w) ==> order vertices by decreasing post order number - Find a sink vertex, output it, delete it. Repeat. Will build ordering backwards
What is special about the first and last vertices in a topological sorting?
First vertex must be a source vertex and last must be a sink
Source vertex and its post-order #
has no incoming edges, highest post-order #
Sink vertex and its post-order #
has not outgoing edges, lowest post-order #
def: strongly connected
two vertices are strongly connected if there is a path from w to v and from v to w (in a directed graph)
def: SCC
Maximal set of strongly connected vertices. only in directed graph
metavertex/metagraph
can replace SCCs with metavertices to create a metagraph. metagraph is always a DAG
SCC Algorithm general idea
find a sink SCC, output it, remove it, and repeat
Why use sink SCC in algorithm?
Running explore on a vertex in sink will return all vertices in that SCC (and no others)
How do we find a vertex in a source SCC and how does this help with the SCC Algorithm?
Vertex with highest post number lies in a source SCC. If we reverse the graph, that vertex will be in a sink SCC
SCC Algorithm
SCC(G):
1. Construct a reverse graph
2. Run DFS on reverse G
3. Order vertices by decreasing post order number
4. Run undirected connected components algorithm on G (i.e. DFS)
Output = topological ordering of SCCs
SCC runtime
O(m+n)
CNF formula
conjunctive normal form formula. AND of several clauses
clause
OR of several literals
literals
x1, !x1, etc
SAT
input: CNF
output: T/F if it can be satisfied (and the assignments)