# Dijkstra's Algorithm

> A way to find the shortest route through a graph where each road has a length.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Dijkstra, Dijkstra Shortest Path, Shortest Path Algorithm

## Think of it like

Think of it like a map app. It tries the closest roads first and keeps the best time to each place.

## Definition

Dijkstra's algorithm finds the shortest path from one node to every other node. It works on a graph whose edges have a length, or weight. It keeps a best-known distance for each node, starting from zero at the start. Each step, it takes the closest node it has not finished and checks its neighbours. A heap makes picking the closest node quick. It only works when no edge has a negative weight.

## Example

Lucy's delivery app finds the quickest route across 400 streets. Dijkstra's algorithm picks a path of 9 minutes over one of 14.

## Why it matters

Route planners, network routers and games all find short paths with it or a close cousin.

## Common mistake

Using it on a graph with negative weights. It can give a wrong answer; other algorithms handle that case.

## Three principles

- **Shortest by weight.** Not by number of steps.
- **Closest first.** A heap picks it fast.
- **No negative weights.** Or it goes wrong.

## Related terms

- [Graph (Data Structure)](https://learn.benibix.com/term/development/graph)
- [Breadth-First Search (BFS)](https://learn.benibix.com/term/development/breadth-first-search)
- [Heap (Data Structure)](https://learn.benibix.com/term/development/heap)
- [Greedy Algorithm](https://learn.benibix.com/term/development/greedy-algorithm)
- [Pathfinding](https://learn.benibix.com/term/development/pathfinding)

---

Source: https://learn.benibix.com/term/development/dijkstras-algorithm
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
