{
  "slug": "graph-bfs",
  "title": "Breadth-First Search",
  "category": "Graphs",
  "difficulty": "medium",
  "complexity": {
    "time": "O(V + E)",
    "space": "O(V)"
  },
  "idea": "BFS visits everything one step away, then everything two steps away, and so on. A queue holds the frontier, and marking nodes seen the moment they are enqueued stops the same node being queued twice. On an unweighted graph this finds shortest paths.",
  "code": [
    "queue = [start]; seen = {start}",
    "while queue not empty:",
    "    cur = queue.pop_front()   # visit",
    "    for nb in neighbours(cur):",
    "        if nb not seen: seen.add(nb); queue.push(nb)"
  ],
  "example": {
    "array": []
  },
  "invariant": "Each step is the real data structure at that step — the picture is a pure function of it.",
  "stepCount": 22,
  "steps": [
    {
      "i": 0,
      "op": "graph",
      "caption": "BFS from A: the queue starts holding just the source.",
      "note": null,
      "codeLine": 1,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "insert",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "A"
          ]
        },
        {
          "label": "visit order",
          "items": []
        }
      ]
    },
    {
      "i": 1,
      "op": "graph",
      "caption": "Take A off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": []
        },
        {
          "label": "visit order",
          "items": [
            "A"
          ]
        }
      ]
    },
    {
      "i": 2,
      "op": "graph",
      "caption": "B is new — mark it seen and add it to the back of the queue.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "insert",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "B"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A"
          ]
        }
      ]
    },
    {
      "i": 3,
      "op": "graph",
      "caption": "C is new — mark it seen and add it to the back of the queue.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "insert",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "B",
            "C"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A"
          ]
        }
      ]
    },
    {
      "i": 4,
      "op": "graph",
      "caption": "Take B off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "C"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B"
          ]
        }
      ]
    },
    {
      "i": 5,
      "op": "graph",
      "caption": "A has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "C"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B"
          ]
        }
      ]
    },
    {
      "i": 6,
      "op": "graph",
      "caption": "C has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "C"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B"
          ]
        }
      ]
    },
    {
      "i": 7,
      "op": "graph",
      "caption": "D is new — mark it seen and add it to the back of the queue.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "insert",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "C",
            "D"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B"
          ]
        }
      ]
    },
    {
      "i": 8,
      "op": "graph",
      "caption": "Take C off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "D"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C"
          ]
        }
      ]
    },
    {
      "i": 9,
      "op": "graph",
      "caption": "A has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "D"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C"
          ]
        }
      ]
    },
    {
      "i": 10,
      "op": "graph",
      "caption": "B has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "D"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C"
          ]
        }
      ]
    },
    {
      "i": 11,
      "op": "graph",
      "caption": "E is new — mark it seen and add it to the back of the queue.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "insert",
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "D",
            "E"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C"
          ]
        }
      ]
    },
    {
      "i": 12,
      "op": "graph",
      "caption": "Take D off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "E"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D"
          ]
        }
      ]
    },
    {
      "i": 13,
      "op": "graph",
      "caption": "B has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "E"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D"
          ]
        }
      ]
    },
    {
      "i": 14,
      "op": "graph",
      "caption": "F is new — mark it seen and add it to the back of the queue.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": null,
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": "insert",
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "E",
            "F"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D"
          ]
        }
      ]
    },
    {
      "i": 15,
      "op": "graph",
      "caption": "Take E off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "F"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E"
          ]
        }
      ]
    },
    {
      "i": 16,
      "op": "graph",
      "caption": "C has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "F"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E"
          ]
        }
      ]
    },
    {
      "i": 17,
      "op": "graph",
      "caption": "F has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": null,
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "active"
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": [
            "F"
          ]
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E"
          ]
        }
      ]
    },
    {
      "i": 18,
      "op": "graph",
      "caption": "Take F off the front of the queue and visit it.",
      "note": null,
      "codeLine": 3,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": []
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E",
            "F"
          ]
        }
      ]
    },
    {
      "i": 19,
      "op": "graph",
      "caption": "D has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "active"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": []
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E",
            "F"
          ]
        }
      ]
    },
    {
      "i": 20,
      "op": "graph",
      "caption": "E has already been seen — skip it.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": "settled",
          "badges": [
            "cur"
          ]
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "active"
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": []
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E",
            "F"
          ]
        }
      ]
    },
    {
      "i": 21,
      "op": "graph",
      "caption": "Queue empty — every reachable node visited, nearest first: A B C D E F.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "nodes": [
        {
          "id": "A",
          "label": "A",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "B",
          "label": "B",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "C",
          "label": "C",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "D",
          "label": "D",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "E",
          "label": "E",
          "text": null,
          "focus": "settled",
          "badges": null
        },
        {
          "id": "F",
          "label": "F",
          "text": null,
          "focus": "settled",
          "badges": null
        }
      ],
      "edges": [
        {
          "from": "A",
          "to": "B",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "A",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "B",
          "to": "C",
          "weight": null,
          "directed": false,
          "tone": null
        },
        {
          "from": "B",
          "to": "D",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "C",
          "to": "E",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "D",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": "settled"
        },
        {
          "from": "E",
          "to": "F",
          "weight": null,
          "directed": false,
          "tone": null
        }
      ],
      "rows": [
        {
          "label": "queue",
          "items": []
        },
        {
          "label": "visit order",
          "items": [
            "A",
            "B",
            "C",
            "D",
            "E",
            "F"
          ]
        }
      ]
    }
  ]
}