Lecture Notes on Dijkstra's Algorithm - Data structures | CS 261, Study notes of Data Structures and Algorithms

Material Type: Notes; Class: DATA STRUCTURES; Subject: Computer Science; University: Oregon State University; Term: Summer 2006;

Typology: Study notes

Pre 2010

Uploaded on 08/31/2009

koofers-user-c8e
koofers-user-c8e 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lesson: Dijkstra’s Algorithm
Dijkstra’s algorithm is used to solve the single source reachability problem on
graphs using the edge-list representation. It is also a nice example of the use of
various different data structures. Imagine a graph such as the following:
We want to find the shortest distance to various cities starting from Pierre. The
graph is represented by a map keyed by a city name. The value stored for each
key is also a map, with a city as key and a weight as value. The map
representation of the above graph is as follows:
Dijkstra’s algorithm uses an internal priority queue of distance/city pairs. This
queue is organized so that the value with smallest distance is at the top of the
queue. Initially the queue contains the starting city and distance zero. The map
of reachable cities is initially zero. As a city if pulled from the queue, if it is already
known to be reachable it is ignored. Otherwise it is placed into the queue of
reachable cities, and the neighbors of the new city are placed into the queue,
adding the distance to the city and the distance to the new neighbor.
The following table shows the values of the priority queue at various stages:
Pierre: 0
Pierre: 0
Pendleton: 2
Pendleton: 2
Phoenix: 6, Pueblo: 10
Phoenix: 6
Pueblo: 9, Peoria 10, Pueblo: 10, Pittsburgh: 16
Pueblo: 9
Peoria: 10, Pueblo: 10, Pierre: 12, Pittsburgh: 16
Peoria: 10
Pueblo: 10, Pierre: 12, Pueblo: 13 Pittsburgh: 15, Pittsburgh: 16
Pittsburgh: 15
Pittsburgh: 16, Pensacola: 19
Pensacola: 19
Phoenix: 24
Notice how duplicates are removed only when pulled from the queue.
pf2

Partial preview of the text

Download Lecture Notes on Dijkstra's Algorithm - Data structures | CS 261 and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Lesson: Dijkstra’s Algorithm

Dijkstra’s algorithm is used to solve the single source reachability problem on graphs using the edge-list representation. It is also a nice example of the use of various different data structures. Imagine a graph such as the following: We want to find the shortest distance to various cities starting from Pierre. The graph is represented by a map keyed by a city name. The value stored for each key is also a map, with a city as key and a weight as value. The map representation of the above graph is as follows: Dijkstra’s algorithm uses an internal priority queue of distance/city pairs. This queue is organized so that the value with smallest distance is at the top of the queue. Initially the queue contains the starting city and distance zero. The map of reachable cities is initially zero. As a city if pulled from the queue, if it is already known to be reachable it is ignored. Otherwise it is placed into the queue of reachable cities, and the neighbors of the new city are placed into the queue, adding the distance to the city and the distance to the new neighbor. The following table shows the values of the priority queue at various stages: Pierre: 0 Pierre: 0 Pendleton: 2 Pendleton: 2 Phoenix: 6, Pueblo: 10 Phoenix: 6 Pueblo: 9, Peoria 10, Pueblo: 10, Pittsburgh: 16 Pueblo: 9 Peoria: 10, Pueblo: 10, Pierre: 12, Pittsburgh: 16 Peoria: 10 Pueblo: 10, Pierre: 12, Pueblo: 13 Pittsburgh: 15, Pittsburgh: 16 Pittsburgh: 15 Pittsburgh: 16, Pensacola: 19 Pensacola: 19 Phoenix: 24 Notice how duplicates are removed only when pulled from the queue.

Simulate Dijstra’s algorithm, only this time using Pensacola as the starting city: