Skip to content
Learnearn.uk » A Level Computer Science Home » Dijkstra’s Algorithm

Dijkstra’s Algorithm

Activity

Activity – introducing path finding algorithms

Today we are going to be exploring different algorithms for finding the shortest path between two points.

To start have a look at the interactive game in the link provided. How do the different algorithms behave?

How does Dijkstra’s work?

Click here for the pathfinding visualization

Videos

Challenge

Programming Challenge

Using Python program an implementation of Dijkstra’s algorithm to find the shortest driving distance between two cities using the data provided.

UK Road Graph

UK Road Sheets File (Download as CSV to use within your program)

UK Roads Matrix

Limitations

Limitations of Dijkstra’s Algorithm

Dijkstra’s algorithm is a great, simple way of finding the shortest path in most situations, however it does have 2 big weaknesses

A lack of heuristics

Dijkstra’s algorithm has no notion of the overall shortest direction to the end goal, so it will actually spend a lot of time searching in completely the wrong direction if the routes in the wrong direction are shorter than the route in the correct direction. It will find the shortest route in the end but it will waste a lot of time.

In small networks this isn’t a problem but when you have massive networks (like road networks or the internet) then it will result in massive inefficiencies.

Negative Weighted Costs

On physical networks with physical distances you can’t have negative weights, but one some networks where you are calculating costs you might have negative costs for a particular leg. Dijkstra’s cant handle these negative costs.

Directed networks

Dijkstra’s algorithm doesn’t always work best when there are directed networks (such as motorways that only run in one direction.

 

Internet Routing

Internal Routing with Shortest Path

 

 

Resources