{
  "id": "graphs/dijkstra",
  "version": 1,
  "deterministic": true,
  "url": "/dsa/graphs/dijkstra",
  "topic": {
    "slug": "graphs",
    "title": "Graphs"
  },
  "title": "Dijkstra's Shortest Path",
  "tagline": "The cheapest route through a weighted map — always finish the nearest place first.",
  "vizKind": "graph",
  "complexity": {
    "time": {
      "best": "O(E log V)",
      "average": "O(E log V)",
      "worst": "O(E log V)"
    },
    "space": "O(V)",
    "growth": "nlogn",
    "note": "With a priority queue (a heap!) to grab the nearest unfinished node, it's O(E log V). Without one you scan every node each round, giving O(V²) — still fine for small dense graphs. This is a real payoff from the Heap lesson."
  },
  "code": {
    "javascript": "function dijkstra(graph, start) {\n  const dist = {};\n  for (const v of graph.nodes) dist[v] = Infinity;\n  dist[start] = 0;\n  const done = new Set();\n\n  while (done.size < graph.nodes.length) {\n    // the unfinished node with the smallest known distance\n    const u = closest(dist, done);\n    if (u === null) break;\n    done.add(u);\n\n    for (const [v, w] of graph.edges[u]) {\n      if (dist[u] + w < dist[v]) {\n        dist[v] = dist[u] + w;\n      }\n    }\n  }\n  return dist;\n}",
    "python": "import heapq\n\ndef dijkstra(graph, start):\n    dist = {v: float('inf') for v in graph}\n    dist[start] = 0\n    done = set()\n\n    pq = [(0, start)]\n    while pq:\n        d, u = heapq.heappop(pq)\n        if u in done: continue\n        done.add(u)\n\n        for v, w in graph[u]:\n            if dist[u] + w < dist[v]:\n                dist[v] = dist[u] + w\n                heapq.heappush(pq, (dist[v], v))\n\n    return dist\n",
    "java": "Map<String,Integer> dijkstra(Graph g, String start) {\n  Map<String,Integer> dist = new HashMap<>();\n  for (String v : g.nodes) dist.put(v, Integer.MAX_VALUE);\n  dist.put(start, 0);\n  Set<String> done = new HashSet<>();\n\n  while (done.size() < g.nodes.size()) {\n    String u = closest(dist, done);\n    if (u == null) break;\n    done.add(u);\n\n    for (Edge e : g.edges.get(u)) {\n      if (dist.get(u) + e.w < dist.get(e.to)) {\n        dist.put(e.to, dist.get(u) + e.w);\n      }\n    }\n  }\n  return dist;\n}",
    "cpp": "map<string,int> dijkstra(Graph& g, string start) {\n  map<string,int> dist;\n  for (auto& v : g.nodes) dist[v] = INT_MAX;\n  dist[start] = 0;\n  set<string> done;\n\n  while ((int)done.size() < (int)g.nodes.size()) {\n    string u = closest(dist, done);\n    if (u.empty()) break;\n    done.insert(u);\n\n    for (auto& [v, w] : g.edges[u]) {\n      if (dist[u] + w < dist[v]) {\n        dist[v] = dist[u] + w;\n      }\n    }\n  }\n  return dist;\n}"
  },
  "defaultInput": [
    1
  ],
  "defaultTarget": null,
  "inputHint": "Pick a start node: 1 = A, up to 7 = G. Numbers on the roads are their cost.",
  "pitfalls": [
    {
      "wrong": "Using Dijkstra on a graph with negative edge weights.",
      "right": "It will confidently return the wrong answer. 'Nearest unfinished node is final' is only true when travelling further can't make things cheaper. Use Bellman–Ford for negative edges."
    },
    {
      "wrong": "Re-finalising a node that's already done.",
      "right": "Once a node is finalised, skip it forever. Popping stale entries out of the priority queue without checking is a classic source of wrong answers and infinite work."
    },
    {
      "wrong": "Confusing Dijkstra with BFS.",
      "right": "BFS finds the fewest *edges*; Dijkstra finds the lowest *total weight*. On an unweighted graph they agree — and Dijkstra reduces to BFS exactly."
    },
    {
      "wrong": "Scanning every node to find the closest, on a big graph.",
      "right": "That's O(V²). Use a priority queue so 'get me the closest' costs O(log V) instead of O(V)."
    }
  ],
  "quiz": [
    {
      "q": "Why can Dijkstra declare the nearest unfinished node's distance final?",
      "options": [
        "Because it checked every possible route first",
        "Because any other route would first have to pass somewhere even further away, so it would cost more",
        "Because it's a guess that usually works",
        "It can't — it revisits nodes later"
      ],
      "answer": 1,
      "why": "That's the whole proof. If a node is the closest thing left, every alternative route to it detours through something more distant — which already costs more. So no cheaper route can exist."
    },
    {
      "q": "What breaks Dijkstra?",
      "options": [
        "Very large graphs",
        "Negative edge weights",
        "Cycles",
        "Disconnected nodes"
      ],
      "answer": 1,
      "why": "Negative edges destroy the argument: travelling further could make a route cheaper, so 'nearest so far is final' stops being true. Bellman–Ford handles that case."
    },
    {
      "q": "What data structure makes Dijkstra fast?",
      "options": [
        "A stack",
        "A hash map",
        "A priority queue (heap)",
        "A linked list"
      ],
      "answer": 2,
      "why": "It constantly needs the closest unfinished node. A heap gives you that in O(log V) instead of scanning all V nodes — turning O(V²) into O(E log V)."
    }
  ],
  "problems": [
    {
      "name": "Network Delay Time",
      "difficulty": "Medium",
      "url": "https://leetcode.com/problems/network-delay-time/"
    },
    {
      "name": "Path with Maximum Probability",
      "difficulty": "Medium",
      "url": "https://leetcode.com/problems/path-with-maximum-probability/"
    },
    {
      "name": "Cheapest Flights Within K Stops",
      "difficulty": "Medium",
      "url": "https://leetcode.com/problems/cheapest-flights-within-k-stops/"
    }
  ],
  "trace": {
    "note": "Each frame is one immutable step: data snapshot, pointers, per-index roles, executing code line, and a one-sentence explanation.",
    "length": 28,
    "frames": [
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "active"
            },
            {
              "id": "B",
              "label": "B ∞",
              "x": 0.35,
              "y": 0.18
            },
            {
              "id": "C",
              "label": "C ∞",
              "x": 0.35,
              "y": 0.82
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": []
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 4,
        "variables": {
          "start": "A",
          "A": 0
        },
        "explanation": "Find the cheapest route from A to everywhere. Every node starts at ∞ — unreachable as far as we know — except A, which costs 0 to reach from itself.",
        "stats": {
          "comparisons": 0,
          "swaps": 0
        },
        "accent": "active"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B ∞",
              "x": 0.35,
              "y": 0.18
            },
            {
              "id": "C",
              "label": "C ∞",
              "x": 0.35,
              "y": 0.82
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "A",
          "cost": 0
        },
        "explanation": "A is the closest unfinished node, at cost 0. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So A's distance is final.",
        "stats": {
          "comparisons": 1,
          "swaps": 0
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B ∞",
              "x": 0.35,
              "y": 0.18,
              "role": "compare"
            },
            {
              "id": "C",
              "label": "C ∞",
              "x": 0.35,
              "y": 0.82
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "compare"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "A",
          "to": "B",
          "edge": 4,
          "viaU": 4,
          "known": "∞"
        },
        "explanation": "Going A → B costs 0 + 4 = 4, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 2,
          "swaps": 0
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "compare"
            },
            {
              "id": "C",
              "label": "C ∞",
              "x": 0.35,
              "y": 0.82
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "B": 4
        },
        "explanation": "Update B to 4. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 2,
          "swaps": 1
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C ∞",
              "x": 0.35,
              "y": 0.82,
              "role": "compare"
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "compare"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "A",
          "to": "C",
          "edge": 2,
          "viaU": 2,
          "known": "∞"
        },
        "explanation": "Going A → C costs 0 + 2 = 2, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 3,
          "swaps": 1
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "compare"
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "C": 2
        },
        "explanation": "Update C to 2. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 3,
          "swaps": 2
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "C",
          "cost": 2
        },
        "explanation": "C is the closest unfinished node, at cost 2. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So C's distance is final.",
        "stats": {
          "comparisons": 4,
          "swaps": 2
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D ∞",
              "x": 0.62,
              "y": 0.5,
              "role": "compare"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "compare"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "C",
          "to": "D",
          "edge": 8,
          "viaU": 10,
          "known": "∞"
        },
        "explanation": "Going C → D costs 2 + 8 = 10, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 5,
          "swaps": 2
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 10",
              "x": 0.62,
              "y": 0.5,
              "role": "compare"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "D": 10
        },
        "explanation": "Update D to 10. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 5,
          "swaps": 3
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 10",
              "x": 0.62,
              "y": 0.5,
              "role": "pivot"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G ∞",
              "x": 0.9,
              "y": 0.8,
              "role": "compare"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "compare"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "C",
          "to": "G",
          "edge": 12,
          "viaU": 14,
          "known": "∞"
        },
        "explanation": "Going C → G costs 2 + 12 = 14, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 6,
          "swaps": 3
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "pivot"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 10",
              "x": 0.62,
              "y": 0.5,
              "role": "pivot"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "compare"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "G": 14
        },
        "explanation": "Update G to 14. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 6,
          "swaps": 4
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 10",
              "x": 0.62,
              "y": 0.5,
              "role": "pivot"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "B",
          "cost": 4
        },
        "explanation": "B is the closest unfinished node, at cost 4. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So B's distance is final.",
        "stats": {
          "comparisons": 7,
          "swaps": 4
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 10",
              "x": 0.62,
              "y": 0.5,
              "role": "compare"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "compare"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "B",
          "to": "D",
          "edge": 5,
          "viaU": 9,
          "known": "10"
        },
        "explanation": "Going B → D costs 4 + 5 = 9, which beats the 10 we had. That's a better route.",
        "stats": {
          "comparisons": 8,
          "swaps": 4
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "compare"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "D": 9
        },
        "explanation": "Update D to 9. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 8,
          "swaps": 5
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "pivot"
            },
            {
              "id": "E",
              "label": "E ∞",
              "x": 0.62,
              "y": 0.12,
              "role": "compare"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "compare"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "B",
          "to": "E",
          "edge": 10,
          "viaU": 14,
          "known": "∞"
        },
        "explanation": "Going B → E costs 4 + 10 = 14, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 9,
          "swaps": 5
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "pivot"
            },
            {
              "id": "E",
              "label": "E 14",
              "x": 0.62,
              "y": 0.12,
              "role": "compare"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "E": 14
        },
        "explanation": "Update E to 14. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 9,
          "swaps": 6
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 14",
              "x": 0.62,
              "y": 0.12,
              "role": "pivot"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "D",
          "cost": 9
        },
        "explanation": "D is the closest unfinished node, at cost 9. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So D's distance is final.",
        "stats": {
          "comparisons": 10,
          "swaps": 6
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 14",
              "x": 0.62,
              "y": 0.12,
              "role": "compare"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "compare"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "D",
          "to": "E",
          "edge": 2,
          "viaU": 11,
          "known": "14"
        },
        "explanation": "Going D → E costs 9 + 2 = 11, which beats the 14 we had. That's a better route.",
        "stats": {
          "comparisons": 11,
          "swaps": 6
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "compare"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "E": 11
        },
        "explanation": "Update E to 11. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 11,
          "swaps": 7
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "pivot"
            },
            {
              "id": "F",
              "label": "F ∞",
              "x": 0.9,
              "y": 0.35,
              "role": "compare"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "compare"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "D",
          "to": "F",
          "edge": 6,
          "viaU": 15,
          "known": "∞"
        },
        "explanation": "Going D → F costs 9 + 6 = 15, which beats the unknown we had. That's a better route.",
        "stats": {
          "comparisons": 12,
          "swaps": 7
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "pivot"
            },
            {
              "id": "F",
              "label": "F 15",
              "x": 0.9,
              "y": 0.35,
              "role": "compare"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "F": 15
        },
        "explanation": "Update F to 15. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 12,
          "swaps": 8
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 15",
              "x": 0.9,
              "y": 0.35,
              "role": "pivot"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "E",
          "cost": 11
        },
        "explanation": "E is the closest unfinished node, at cost 11. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So E's distance is final.",
        "stats": {
          "comparisons": 13,
          "swaps": 8
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 15",
              "x": 0.9,
              "y": 0.35,
              "role": "compare"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "compare"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "E",
          "to": "F",
          "edge": 3,
          "viaU": 14,
          "known": "15"
        },
        "explanation": "Going E → F costs 11 + 3 = 14, which beats the 15 we had. That's a better route.",
        "stats": {
          "comparisons": 14,
          "swaps": 8
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 14",
              "x": 0.9,
              "y": 0.35,
              "role": "compare"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "sorted"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 14,
        "variables": {
          "F": 14
        },
        "explanation": "Update F to 14. This is called \"relaxing\" the edge — we found a shortcut and wrote it down.",
        "stats": {
          "comparisons": 14,
          "swaps": 9
        },
        "accent": "found"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 14",
              "x": 0.9,
              "y": 0.35,
              "role": "sorted"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "pivot"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "sorted"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E",
            "F"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "F",
          "cost": 14
        },
        "explanation": "F is the closest unfinished node, at cost 14. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So F's distance is final.",
        "stats": {
          "comparisons": 15,
          "swaps": 9
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 14",
              "x": 0.9,
              "y": 0.35,
              "role": "sorted"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "compare"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "sorted"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4,
              "role": "compare"
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E",
            "F"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 13,
        "variables": {
          "from": "F",
          "to": "G",
          "edge": 4,
          "viaU": 18,
          "known": "14"
        },
        "explanation": "Going F → G costs 14 + 4 = 18, which is no better than the 14 we already know. Ignore it.",
        "stats": {
          "comparisons": 16,
          "swaps": 9
        },
        "accent": "compare"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 14",
              "x": 0.9,
              "y": 0.35,
              "role": "sorted"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "sorted"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "sorted"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E",
            "F",
            "G"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 9,
        "variables": {
          "finalising": "G",
          "cost": 14
        },
        "explanation": "G is the closest unfinished node, at cost 14. Nothing can ever reach it more cheaply — any other route would have to pass through something even further away. So G's distance is final.",
        "stats": {
          "comparisons": 17,
          "swaps": 9
        },
        "accent": "sorted"
      },
      {
        "data": {
          "nodes": [
            {
              "id": "A",
              "label": "A 0",
              "x": 0.1,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "B",
              "label": "B 4",
              "x": 0.35,
              "y": 0.18,
              "role": "sorted"
            },
            {
              "id": "C",
              "label": "C 2",
              "x": 0.35,
              "y": 0.82,
              "role": "sorted"
            },
            {
              "id": "D",
              "label": "D 9",
              "x": 0.62,
              "y": 0.5,
              "role": "sorted"
            },
            {
              "id": "E",
              "label": "E 11",
              "x": 0.62,
              "y": 0.12,
              "role": "sorted"
            },
            {
              "id": "F",
              "label": "F 14",
              "x": 0.9,
              "y": 0.35,
              "role": "sorted"
            },
            {
              "id": "G",
              "label": "G 14",
              "x": 0.9,
              "y": 0.8,
              "role": "sorted"
            }
          ],
          "edges": [
            {
              "from": "A",
              "to": "B",
              "weight": 4,
              "role": "sorted"
            },
            {
              "from": "A",
              "to": "C",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "D",
              "weight": 5,
              "role": "sorted"
            },
            {
              "from": "B",
              "to": "E",
              "weight": 10,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "D",
              "weight": 8,
              "role": "sorted"
            },
            {
              "from": "C",
              "to": "G",
              "weight": 12,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "E",
              "weight": 2,
              "role": "sorted"
            },
            {
              "from": "D",
              "to": "F",
              "weight": 6,
              "role": "sorted"
            },
            {
              "from": "E",
              "to": "F",
              "weight": 3,
              "role": "sorted"
            },
            {
              "from": "F",
              "to": "G",
              "weight": 4
            }
          ],
          "directed": false,
          "visited": [
            "A",
            "C",
            "B",
            "D",
            "E",
            "F",
            "G"
          ]
        },
        "pointers": [],
        "highlights": [],
        "codeLine": 19,
        "variables": {
          "result": "A=0  B=4  C=2  D=9  E=11  F=14  G=14"
        },
        "explanation": "Every node is finalised. Cheapest cost from A: A=0  B=4  C=2  D=9  E=11  F=14  G=14. Dijkstra got there by always finishing the nearest node first — a greedy choice that happens to be provably correct, so long as no edge is negative.",
        "stats": {
          "comparisons": 17,
          "swaps": 9
        },
        "accent": "sorted"
      }
    ]
  }
}