Lecture 12: Practice Problems

1. Time Complexity

If we use a simple Unordered Array for the Priority Queue in Dijkstra, what is the complexity?

Show Answer

O(V^2).

Extract-Min takes O(V) (linear scan). We do it V times. Total V^2.

Edge updates take O(E) total.

This is actually better for dense graphs than the Binary Heap version O(E log V)!

2. Path Reconstruction

After running Dijkstra, how do we print the path from s to v?

Show Answer

Backtrack using pi pointers.

Start at v. Go to pi[v]. Repeat until s.

Then reverse the list.