CZ
CalcyZone
computer-science Verified Precision Tool

Dijkstra Algorithm Calculator & Visualizer

Step-by-step Dijkstra shortest path algorithm runner with distance tables, priority queue state, and edge relaxation logs.

Interactive Algorithm Visualizer

Dijkstra's Algorithm

Enter your custom input data → Run the real algorithm engine → Observe step transitions.

⚙️ Customize Algorithm Input Data

Step 1 of 12⚡ Algorithm Running
WHAT HAPPENED?

Initialized source node A

WHY?

Dijkstra begins greedily at the start node

WHAT CHANGED?

Set dist[A] = 0 and all other nodes to Infinity

Interactive SVG Graph Canvas

421582Ad=0Bd=Cd=Dd=Ed=
Visited SetNone
Current NodeA

Mathematical Formula

dist[v] = min(dist[v], dist[u] + weight(u, v))

Overview & Explanation

Dijkstra algorithm calculates the shortest path from a starting node to all other nodes in a weighted graph with non-negative edge weights.

How It Works

  • Initialize distance of start node to 0 and all other nodes to Infinity.
  • Extract unvisited node with smallest tentative distance.
  • Relax all outgoing edges to unvisited neighbors.
  • Repeat until all reachable nodes are visited.

Practical Applications

  • GPS Routing & Mapping (Google Maps)
  • Network Packet Routing (OSPF protocol)

Dijkstra Step-by-Step Example

Shortest path on graph A-B(4), A-C(2), C-B(1), C-D(5), B-D(2)

1

Init

Extract A (dist 0)

= Relax A-B (4), A-C (2)
2

Extract C

Extract C (dist 2)

= Relax C-B (2+1=3 < 4) -> dist[B]=3
3

Extract B

Extract B (dist 3)

= Relax B-D (3+2=5) -> dist[D]=5
4

Complete

Reconstruct Path

= Path: A -> C -> B -> D (Dist: 5)

Frequently Asked Questions

Why does Dijkstra fail with negative edge weights?
Dijkstra assumes that adding an edge to a path only increases path length. Negative edges violate this greedy assumption. Use Bellman-Ford instead.