Lecture 8: DFS Tree of Discovery + Topological Sort Flashcards
Topological Sort
For A DAG is a linear ordering of vertices in a graph G, such that for every directed edge u->v, u comes before v in ordering
Application of DFS
Which of the following is true about a graph that contains a topological ordering?
A. There must be a vertex with no incoming edges.
B. The graph must be sparse.
C. The graph must be a DAG.
D. Both A and C
E. Both A and B
Both A and C
Some observations:
1. There can be more than one valid topological
ordering for a given graph G.
2. There must be at least one “source vertex” with
no incoming edges.
3. There must be at least one “sink vertex” with no
outgoing edges.
4. There cannot be any cycles in the graph (i.e., G
must be a DAG)
What is the maximum number of edges in an undirected graph with n vertices?
A. n-1
B. n
C. n(n-1)/2
D. n^2
E. None of the above
Ans: n(n-1)/2
What is the maximum number of edges in an undirected graph with n vertices that is acyclic?
A. n-1
B. n
C. n(n-1)/2
D. n^2
E. None of the above
Ans: A: n-1
Ex:
a-b-c-d
What is the maximum number of edges in a DAG with n vertices?
A. n-1
B. n
C. n(n-1)/2
D. n^2
E. None of the above
Ans: C: n(n-1)/2
1st connects to n-1
2nd connects to n-2
3rd connects to n-3
.
.
n(n-1)/2