

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
Material Type: Notes; Class: DATA STRUCTURES; Subject: Computer Science; University: Oregon State University; Term: Summer 2006;
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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: