

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Dijkstra's algorithm for solving the Single Source Shortest Path (SSSP) problem in graphs with non-negative edge weights. It reviews relevant definitions such as shortest path and negative weight cycle, and provides the pseudocode for the algorithm. The document also includes a runtime analysis of the algorithm and discusses the concept of greedy algorithms. It is likely related to university topics such as data structures and algorithms, graph theory, and computer science.
Typology: Lecture notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Dijkstra’s—Monday, October 31 / Tuesday, November 1
In the Single Source Shortest Path (SSSP) Problem, we are given a graph G = (V, E), and we want to find a shortest path from a given source vertex s ∈ V to each vertex v ∈ V. From Recitation 6, we proved that BFS solves this problem for unweighted graphs. However, for weighted graphs, we need something a little more robust. Thus, Dijkstra’s algorithm is an algorithm that solves this problem for graphs with non-negative edge weights; some relevant definitions are as follows:
Shortest Path: A path from vertex s to vertex t with the property that no other such path has a lower total edge weight.
Negative Weight Cycle: A cycle with weights that sum to a negative number.
From Recitation 5, we proved that BFS solves the “Single Source Shortest Path” problem for unweighted graphs. However, for weighted graphs, we need something a little more robust. Dijkstra’s algorithm finds the shortest path between two given vertices in a weighted graph, assuming that the graph’s edge weights are non-negative. The running time of the algorithm is O(|E| log |V | + |V | log |V |) when the graph is implemented using adjacency lists. The pseudocode for the algorithm can be found here.
Runtime Analysis
The running time of Dijkstra’s algorithm has two terms: |E| log |V | and |V | log |V |. We first consider the |V | log |V | term: each Extract-Min operation takes O(log |V |) time, and this operation is called |V | times because there are |V | vertices.
The |E| log |V | term has to do with the relaxation step of Dijkstra’s algorithm. Each edge examined may re- sult in a relaxation of the neighboring node in the heap — a Decrease-Key operation that takes O(log |V |) time. The number of vertices examined in the for loop is bounded by the total degree of all vertices, as each vertex is added and popped exactly once from the min-heap. This value is 2|E| by the Handshaking Lemma, so in the worst-case we have 2|E| decrease-key operations, for a total of O(|E| log |V |).
This analysis works for easily proving our runtime, but we can actually do a better analysis. Each edge (u, v) can only cause one relaxation, not 2 as the Handshaking Lemma suggests. This is because (u, v) is explored only when node u is popped from the min-heap. This means that when (u, v) is explored from node v, we know node u has already been removed, so its key cannot be decreased. Hence, the O(|E| log |V |) term comes from the O(log |V |) cost of a Decrease-Key operation, which is called at most |E| times overall.
Greedy Algorithms
A greedy algorithm is an algorithm that always makes the locally optimal choice — the best available choice at that moment—in order to find the best globally optimal solution. Greedy algorithms do not
always yield optimal solutions, but for many problems they do. Note that Dijkstra’s algorithm solves the “Single Source Shortest Path” problem by following this paradigm — it uses a priority queue structure that always yields the node with the shortest distance from the source node when polled. Consider the set S of vertices in Dijkstra’s whose final shortest-path weights from the source have already been determined. At each step in the algorithm, since we ultimately want to find the shortest path from our source, we use our priority queue to make the locally optimal choice by adding the node with the current shortest distance from the source node to the set S.
Find the shortest paths from A:
(From CLRS 24.3-6) We are given a directed graph G = (V, E) where each edge (u, v) ∈ E has an associated value r(u, v) ∈ [0, 1] that represents the reliability of a communication channel from u to v. We thus interpret r(u, v) as the probability that the channel from u to v will not fail, and we assume that these probabilities are independent. Design an efficient algorithm to find the most reliable path (lowest failure probability) between a vertex s and any other vertex in the graph.