Mazes are often simple puzzles for humans, but they present a great programming problem that we can solve using shortest-path techniques like Dijkstra’s algorithm.

## A Refresher on Dijkstra’s Algorithm

Dijkstra’s Algorithm is one of the more popular basic graph theory algorithms. It is used to find the shortest path between nodes on a directed graph. We start with a source node and known edge lengths between nodes.

We first assign a distance-from-source value to all the nodes. Node *s* receives a 0 value because it is the source; the rest receive values of ∞ to start.

Our node of interest is the smallest-value unprocessed node (shown in grey), which is *s*. First, we “relax” each adjacent vertex to our node of interest, updating their values to the minimum of their current value or the node of interest’s value plus the connecting edge length.

Node *s* is now finalized (black) and its neighbors _a _and _b _have taken on new values. The new node of interest is *b*, so we repeat the process of “relaxing” *b*’s adjacent nodes and finalizing the shortest-path value of *b*.

#towards-data-science #programming #data-science #image-processing #algorithms