DAG Shortest Path Flashcards

1
Q

What is a Directed Acyclic Graph (DAG)?

A

A graph with directed edges and no cycles.

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

Why can we optimize shortest path algorithms on DAGs?

A

Because DAGs have no cycles, allowing us to use topological ordering to process vertices efficiently.

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

What is the key idea for finding shortest paths in DAGs?

A

Topologically sort the graph, then relax all edges from each vertex in topological order.

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

What is the time complexity of the shortest path algorithm on a DAG?

A

Θ(V + E), where V is the number of vertices and E is the number of edges.

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

What is topological sorting?

A

An ordering of vertices such that for every directed edge u -> v, vertex u comes before v.

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

What is the relaxation condition for an edge (u, v) with weight w?

A

If dist[v] > dist[u] + w, then update dist[v] = dist[u] + w.

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

How many rounds of relaxation are needed for shortest path in a DAG?

A

Only one pass through the vertices in topological order.

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

What is the best algorithm when all edge weights are 1?

A

Breadth-First Search (BFS).

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

Why does BFS work when all edge weights are 1?

A

BFS visits vertices in order of their depth from the source, matching shortest paths by edge count.

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

What is the time complexity of BFS?

A

Θ(V + E).

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

What is the best algorithm when all edge weights are non-negative?

A

Dijkstra’s algorithm.

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

When should you use Bellman-Ford?

A

When the graph may contain negative edge weights.

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

What does Dijkstra’s algorithm require about edge weights?

A

All edge weights must be non-negative.

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

What makes the DAG shortest path method faster than Bellman-Ford?

A

It uses a single pass and leverages topological order instead of V-1 passes.

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

What is the first step in DAG shortest path algorithm?

A

Perform a topological sort of the graph.

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

What is the second step in DAG shortest path algorithm?

A

Initialize distances and relax all edges from each vertex in topological order.