Lecture 14: Dijkstra's Shortest Path Algorithm Flashcards

1
Q

Why we can’t simply use our current BFS algorithm to locate the shortest path?

A

BFS only works for the shortest path in an unweighted graph

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

Like MST, the shortest path problem doesn’t change when edges have negative weights?

A

This is sometimes true when the edges have negative weights

N.B: need more info

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

Single Source Shortest Path Algorithm assumptions

A
  • edge weights are positive: our algo ONLY works if edge weights are positive. For negative edge weights, there are other algorithms.
  • Connected: making things easier, we easily code around this otherwise
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Dijkstra’s Shortest Path Algorithm and runtime analysis

A

A modification of prims - instead of picking the smallest edge weight next, Dijkstra picks the edge that minimizes the total cost

  1. Initialize the cost of each vertex to infinity
  2. initialize the cost of the source vertex to 0
  3. WHILE undiscovered vertices are left in the graph
    a. Select undiscovered vertex U with the lowest cost and mark as discovered
    b. FOR EACH vertex V adjacent to u
    V’s cost = min(V’s old cost, U’s cost + cost of (U, V))
    C. Mark U as processed
  4. END-WHILE

Analysis
- Since Dijkstra relies on our current version of Prim’s algorithm as its backbone, we can guess O(V^2)
- The bottleneck is finding the next minimum const vertex to explore for every vertex O(V^2)
- We will see some tricks to make this faster later on

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

Dijkstra’s comparison to prims

A

Finds the shortest path <-> finds MST
Undirected & Directed <-> Undirected
No negative edge weights <-> handles negative edge weights

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