Lecture 8: DFS Tree of Discovery + Topological Sort Flashcards

1
Q

Topological Sort

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Ans: n(n-1)/2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

Ans: A: n-1
Ex:

a-b-c-d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly