L14 (Connectivity, DAGs and Topo Sort) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

An undirected graph is “connected” under what condition?

A

If there is a path between all pairs of vertices Vi, Vj

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

What is a “connected component” in an undirected graph G?

A

A connected component is a subgraph of G (any graph whose vertex and edges are subsets of G) such that:
1. the subgraph is connected, and
2. no vertex in the subgraph is connected to any vertex outside

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

We can count the number of connected components in a graph using DFS/BFS by adding what modification?

A

Adding a global counter and a hashSet, and pruning whenever a visited node is re-visited

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

What do the pre-visit and post-visit ordering mean in DFS/BFS in the context of a clock?

A

pre-visit: the “time” that explore is first called on a vertex
post-visit: the “time” that the explore call is finished

Combining these two, we get a time interval

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • What is a cycle in a graph?
  • Under what condition is a graph considered a “tree”?
  • Under what condition is a graph considered a “forest”?
A
  • A cycle in a graph is a path that starts and ends at the same vertex
  • A graph is considered a tree if it is connected AND does not contain any cycles
  • A graph is considered a forest if does not contain any cycles (a collection of trees)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a DFS forest?

A

It is the collection of rooted trees that gets created when running a DFS on a graph

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

Write an algorithm to check if a directed graph G contains a cycle

A
  1. For each node, build a DFS forest
  2. If there are any duplicate nodes (or back edges) in any of the DFS forests, then there is a cycle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Topological Ordering. Is it possible to have this for cyclic graphs?

A

Topological Ordering is an ordering of vertices such that for each edge (u, v) in the graph, the vertex ‘u’ comes before the vertex ‘v’ in the ordering. This is not possible for cyclic graphs

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

If we perform a topological sort on a graph, what can we say about the post-visit values of the result?

A

It will be descending in post-values. The vertex with the highest “post” number will come first, and the vertex with the lowest “post” value will come last

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

What does it mean for a graph to be “Strongly connected”?

A

A graph is strongly connected if for every pair of vertices “u” and “v”, there is a directed path from “u” to “v” and “v” to “u”

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

What does it mean for a graph to be “Weakly connected”?

A

A graph is weakly connected if it is connected when the direction on each edge is ignored (it becomes an undirected graph)

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

What is a “strongly connected component” in a graph G?

A

A subgraph of the graph G which is strongly connected (there is a path from vertex U to V for every pair of vertices U and V)

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

What is a tree edge?

A

(u, v) is a tree edge if it is in the DFS forest, and v is visited in between the pre-visit and post-visit of u

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

What is a forward edge?

A

(u, v) is a forward edge if it is NOT in the DFS edge, and v is visited in between pre-visit and post-visit of u

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

What is a back edge?

A

(u, v) is a back edge if v is an ancestor of u, and u is visited in between pre-visit and post-visit of v

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

What is a cross edge?

A

(u, v) is a cross edge if (pre-visit u, post-visit u) does not overlap with (pre-visit v, post-visit v).

This edge would not be in the DFS forest