Dijkstra's algorithm is a graph search algorithm that computes the shortest paths from a single source node to all other nodes in a weighted graph with non-negative edge weights. It operates by iteratively expanding the frontier from the source, always selecting the node with the smallest known distance, a strategy known as a greedy algorithm. This guarantees optimality for graphs without negative cycles, making it a cornerstone for motion planning in robotics and network routing protocols like OSPF.
Glossary
Dijkstra's Algorithm

What is Dijkstra's Algorithm?
A foundational graph search algorithm for finding optimal paths in weighted networks, central to robotic navigation and network routing.
In embodied intelligence systems, Dijkstra's algorithm is often applied to discretized representations of an environment, such as a grid or graph of waypoints, to find the minimum-cost trajectory for a robot. While powerful for global planning on static maps, its exhaustive search can be computationally intensive for large state spaces, leading to the use of heuristic-guided variants like A search*. Its core principle of optimal substructure—where the shortest path to a node contains the shortest paths to intermediate nodes—is fundamental to many subsequent trajectory optimization and dynamic programming methods.
Key Characteristics of Dijkstra's Algorithm
Dijkstra's algorithm is a foundational graph search algorithm for finding the shortest paths from a single source node to all other nodes in a weighted graph with non-negative edge weights. Its core characteristics define its behavior, guarantees, and limitations within motion planning and broader computational contexts.
Single-Source Shortest Paths
Dijkstra's algorithm solves the Single-Source Shortest Path (SSSP) problem. From a designated source node, it computes the shortest path distance (and can reconstruct the path) to every other reachable node in the graph. This is in contrast to algorithms like Floyd-Warshall, which compute all-pairs shortest paths, or A*, which finds a path to a single goal. The algorithm maintains a tentative distance for each node, which it iteratively finalizes in order of increasing distance from the source.
Greedy Optimality & Non-Negative Weights
The algorithm operates on a greedy principle. At each step, it selects the unvisited node with the smallest known tentative distance and finalizes it, declaring that distance as optimal. This greedy choice is guaranteed to be correct only if all edge weights are non-negative. A negative weight could create a cycle that reduces the total path distance, violating the assumption that a finalized distance is minimal. For graphs with negative weights, the Bellman-Ford algorithm must be used instead.
Computational Complexity
The time complexity of Dijkstra's algorithm depends heavily on the data structure used for the priority queue that selects the next node to visit.
- Simple Array: O(|V|²) - Suitable for dense graphs.
- Binary Heap Priority Queue: O((|E| + |V|) log |V|) - The standard efficient implementation for sparse graphs common in robotics.
- Fibonacci Heap: O(|E| + |V| log |V|) - Asymptotically better for very large, sparse graphs.
Here, |V| is the number of vertices (nodes) and |E| is the number of edges.
Graph Abstraction for Planning
In motion planning, the robot's configuration space (C-space) is discretized into a graph for Dijkstra's algorithm to search.
- Nodes represent discrete robot states or configurations.
- Edges represent feasible transitions between states (e.g., small motions).
- Edge Weights encode the cost of a transition, such as distance, time, energy consumption, or a penalty for proximity to obstacles. This transforms the continuous planning problem into a discrete graph search, where the output is the minimum-cost sequence of states from start to goal.
Comparison with A* Search
While both find shortest paths, key differences are crucial for performance:
- Dijkstra: Explores uniformly in all directions from the source. It finds optimal paths to all nodes.
- A*: Uses a heuristic function (e.g., Euclidean distance to goal) to guide exploration preferentially toward the goal. It is typically faster for single-goal queries but requires an admissible heuristic (never overestimates cost) to guarantee optimality. Dijkstra is equivalent to A* with a heuristic function of zero. In robotics, A* is often preferred for point-to-point planning, while Dijkstra's property of exploring the entire reachable space can be useful for multi-goal planning or building distance maps.
Foundational Role in Advanced Planners
Dijkstra's algorithm is not just a standalone planner; it is a core subroutine in more advanced robotic systems:
- Distance Transform: Used to compute a gradient or cost-to-go map from goal regions, which can guide local planners or sampling-based algorithms.
- Probabilistic Roadmap (PRM): Once a roadmap graph is constructed, Dijkstra's algorithm is used to find the shortest path within it.
- Dynamic Window Approach (DWA): The global path, often computed by Dijkstra or A*, provides the objective for the local, reactive planner. Its guarantee of global optimality (within the discretized graph) makes it a trusted component for generating reference paths in hierarchical planning architectures.
Dijkstra's Algorithm vs. Other Search Methods
A technical comparison of Dijkstra's Algorithm against other fundamental graph search and pathfinding methods used in robotics motion planning.
| Feature / Metric | Dijkstra's Algorithm | A* Search | Breadth-First Search (BFS) | Greedy Best-First Search |
|---|---|---|---|---|
Primary Objective | Find shortest paths from a single source to all nodes | Find shortest path from a single source to a single goal | Find any path, exploring uniformly in all directions | Find a path quickly, not necessarily the shortest |
Graph Type | Weighted graph (non-negative edges) | Weighted graph (non-negative edges) | Unweighted graph | Weighted or unweighted graph |
Optimality Guarantee | ||||
Completeness Guarantee | ||||
Heuristic Use | ||||
Time Complexity (Worst-Case) | O(|E| + |V| log |V|) with priority queue | O(|E|) but depends heavily on heuristic quality | O(|V| + |E|) | O(|V| + |E|) |
Space Complexity | O(|V|) | O(|V|) | O(|V|) | O(|V|) |
Typical Data Structure | Priority Queue (Min-Heap) | Priority Queue (Min-Heap) | Queue (FIFO) | Priority Queue (Min-Heap) |
Best For (Robotics Context) | Computing all possible shortest paths for global costmaps | Efficient, optimal point-to-point navigation with a good heuristic | Exploring an unknown, unweighted grid to find any reachable goal | Fast, approximate planning where optimality is secondary to speed |
Frequently Asked Questions
Dijkstra's algorithm is a foundational graph search method for finding shortest paths, with critical applications in robotic motion planning, network routing, and logistics. These FAQs address its core mechanics, limitations, and role in modern autonomous systems.
Dijkstra's algorithm is a graph search algorithm that finds the shortest paths from a single source node to all other nodes in a weighted graph with non-negative edge weights. It works by iteratively exploring the graph, always expanding the node with the smallest known distance from the source. It maintains two sets: a settled set of nodes whose shortest distance is finalized, and a priority queue (often a min-heap) of unsettled nodes. The algorithm greedily selects the node with the minimum tentative distance from the queue, adds it to the settled set, and relaxes its outgoing edges—updating the distances to its neighbors if a cheaper path is found through the current node. This process repeats until the queue is empty, guaranteeing optimal shortest paths for all reachable nodes.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms in Motion Planning
Dijkstra's algorithm is a cornerstone for pathfinding in weighted graphs. Understanding its relationship to other key algorithms and concepts is essential for robotics engineers and developers working on navigation and planning systems.
A* Search Algorithm
A* is an informed graph search and pathfinding algorithm that extends Dijkstra's by incorporating a heuristic function to estimate the cost to the goal. This prioritizes exploration towards the target, making it dramatically more efficient for single-goal queries.
- Core Mechanism: Combines the actual cost from the start (
g(n)) with a heuristic estimate to the goal (h(n)), evaluating nodes byf(n) = g(n) + h(n). - Relation to Dijkstra: When the heuristic
h(n)is set to zero for all nodes, A* degenerates exactly into Dijkstra's algorithm. - Primary Use: Favored in robotics and video games for finding optimal paths when a good heuristic (like Euclidean distance) is available.
Configuration Space (C-Space)
Configuration Space is the fundamental abstraction where motion planning occurs. It represents every possible state of a robot as a single point, transforming the physical world into a mathematical space where obstacles become forbidden regions.
- Purpose: Converts the complex problem of moving a physical shape into the simpler problem of navigating a point through a space.
- Connection to Dijkstra: Dijkstra's algorithm operates on a discrete graph representation of the free space within C-Space. The graph's nodes are sampled configurations, and edges are valid transitions between them.
- Dimensionality: For a robotic arm with N joints, C-Space is N-dimensional, making exhaustive search (like a naive grid-based Dijkstra) computationally intractable, leading to sampling-based methods.
Probabilistic Roadmap (PRM)
Probabilistic Roadmap is a sampling-based motion planning algorithm that constructs a graph network (roadmap) in the robot's free configuration space. It is designed for multiple queries in the same static environment.
- Two-Phase Process: 1) Learning Phase: Randomly sample collision-free configurations and connect nearby ones with local paths. 2) Query Phase: Connect specific start/goal points to the roadmap and use a graph search (like Dijkstra or A*) to find a path.
- Contrast with Dijkstra: PRM does not search the entire space exhaustively. It builds a sparse graph that captures the connectivity of the environment, upon which Dijkstra's algorithm can then efficiently find paths.
- Application: Ideal for high-dimensional C-Spaces where constructing a complete grid for Dijkstra is impossible.
Weighted Graph
A Weighted Graph is the fundamental data structure on which Dijkstra's algorithm operates. It consists of vertices (nodes) and edges, where each edge has an associated numerical weight or cost.
- Representation in Robotics: Nodes represent discrete robot states (e.g., grid cells, sampled configurations). Edge weights can represent distance, time, energy consumption, traversal difficulty, or risk.
- Algorithm Requirement: Dijkstra's algorithm requires non-negative edge weights. The presence of negative weights invalidates its optimality guarantee and can cause infinite loops.
- Construction: The challenge in motion planning is often in constructing a meaningful graph that accurately reflects the robot's dynamics and environmental costs before Dijkstra is even applied.
Shortest Path Problem
The Shortest Path Problem is the classic optimization problem of finding a path between two vertices in a graph such that the sum of the weights of its constituent edges is minimized. Dijkstra's algorithm is one of the most famous and fundamental solutions.
- Problem Class: Dijkstra solves the single-source shortest path problem, finding the shortest path from a source node to all other nodes in the graph.
- Optimality: For graphs with non-negative weights, Dijkstra's algorithm is guaranteed to produce optimal (minimum-cost) paths.
- Extensions in Robotics: In physical systems, the "shortest" path is often not just geometric distance but may optimize for smoothness (jerk), energy, or time, leading to trajectory optimization built on top of an initial geometric path.
Breadth-First Search (BFS)
Breadth-First Search is a fundamental graph traversal algorithm that explores all nodes at the present "depth" level before moving to nodes at the next depth level. It operates on unweighted graphs.
- Relation to Dijkstra: Dijkstra's algorithm can be viewed as a generalization of BFS for weighted graphs. If all edge weights are equal and positive, Dijkstra's exploration order becomes identical to BFS.
- Cost Metric: BFS finds the path with the fewest number of edges (hops). Dijkstra finds the path with the lowest cumulative edge weight.
- Use Case: In robotics, BFS might be used for simple grid-based planning where movement cost to all adjacent cells is identical (e.g., a vacuum robot). Dijkstra is used when costs vary (e.g., rough terrain vs. smooth floor).

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us