Prove Dijkstra correct for non-negative weights
Analyze the prove dijkstra correct for non-negative weights.
Examples
Input: "proof_case_1"
Output: true
Input: "proof_case_2"
Output: true
Hints
Start by recalling the core idea of Dijkstra's algorithm: it greedily selects the node with the smallest tentative distance, updates its neighbors, and repeats until all nodes are processed. How does this greedy choice ensure correctness for non-negative weights?
Consider the invariant maintained by Dijkstra's algorithm: at each step, the tentative distance of a node is the shortest path distance if it has been finalized. Prove this invariant holds by induction, using the fact that non-negative weights prevent later updates from improving distances.
To formalize the proof, assume for contradiction that Dijkstra's algorithm fails to find the shortest path to some node. Show that this leads to a contradiction by analyzing the first node where the shortest path is incorrectly computed, leveraging the non-negativity of edge weights to derive the inconsistency.
Prove Dijkstra correct for non-negative weights
Analyze the prove dijkstra correct for non-negative weights.