Shortest Path Flashcards

1
Q

Front

A

Back

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

What is the shortest path problem?

A

Given a weighted directed graph, find the path from source s to destination t with the least total weight.

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

Why is the shortest path problem important?

A

Used in navigation (Google Maps), logistics (FedEx, UPS), network routing, AI pathfinding in games.

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

What are the types of shortest path problems?

A

Single source, All pairs, and Single destination (can be reduced to single source via transpose).

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

What is the output of a shortest path algorithm?

A

A cost table (shortest distances) and a parent table (to reconstruct paths).

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

How do shortest paths relate to tree structures?

A

All shortest paths from a source form a tree-like structure rooted at that source.

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

What is the optimal substructure property of shortest paths?

A

Any subpath of a shortest path is also a shortest path.

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

How can you recover a path using the parent table?

A

Trace back from destination using parent pointers until reaching the source.

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

What is the formula for the weight of a path P = [v0, v1, …, vk]?

A

Sum of edge weights: weight(P) = ∑ w(vi−1, vi) from i = 1 to k.

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

What is the effect of positive or zero-weight cycles?

A

They do not help reduce the path cost and can be safely ignored.

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

What is the effect of negative-weight cycles?

A

They make shortest paths undefined or -∞ due to infinite improvements.

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

How can you detect a negative-weight cycle?

A

Using Bellman-Ford algorithm by checking for further improvements after n-1 iterations.

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

What is the general pseudocode pattern for shortest path algorithms?

A

Initialize distances and parents, relax all edges repeatedly to find shortest paths.

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

What is stored in the parent table?

A

The previous vertex on the shortest path to a destination.

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

How do you reconstruct the path from s to v?

A

Follow parent pointers from v back to s and reverse the path.

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

What does it mean to solve a single-destination shortest path problem?

A

Find shortest paths to one destination from all sources by reversing all edges.

17
Q

Why is storing only the last path-one node sufficient?

A

It allows full path reconstruction without storing entire path lists.

18
Q

Why do negative-weight cycles corrupt shortest path answers?

A

Because they allow you to loop infinitely and decrease path cost without bound.

19
Q

What is the ‘foreign taxi’ analogy for negative-weight cycles?

A

A driver takes you on a long detour charging extra—reflects unpredictable cost inflation.

20
Q

What data structure can shortest path algorithms use for efficiency?

A

Priority queues (e.g. in Dijkstra), arrays (Bellman-Ford), or matrices (Floyd-Warshall).

21
Q

How does dynamic programming apply to shortest path problems?

A

Use memoization to store shortest costs and reuse sub-results (optimal substructure).