| 1 | Initialize | - | [0] | {0} | [0:0, others:∞] | [0:-1, others:-1] | Graph nodes: 0-5; Start at node 0 |
| 2 | Dequeue | 0 | [] | {0} | [0:0, others:∞] | [0:-1, others:-1] | Visit node 0 |
| 3 | Visit neighbors | 0 | [] | {0} | [0:0, others:∞] | [0:-1, others:-1] | Neighbors of 0: 1, 2 |
| 4 | Enqueue neighbor 1 | 0 | [1] | {0,1} | [0:0,1:1, others:∞] | [0:-1,1:0, others:-1] | Mark 1 visited, distance=1, parent=0 |
| 5 | Enqueue neighbor 2 | 0 | [1,2] | {0,1,2} | [0:0,1:1,2:1, others:∞] | [0:-1,1:0,2:0, others:-1] | Mark 2 visited, distance=1, parent=0 |
| 6 | Dequeue | 1 | [2] | {0,1,2} | [0:0,1:1,2:1, others:∞] | [0:-1,1:0,2:0, others:-1] | Visit node 1 |
| 7 | Visit neighbors | 1 | [2] | {0,1,2} | [0:0,1:1,2:1, others:∞] | [0:-1,1:0,2:0, others:-1] | Neighbors of 1: 0, 3 |
| 8 | Skip neighbor 0 (visited) | 1 | [2] | {0,1,2} | [0:0,1:1,2:1, others:∞] | [0:-1,1:0,2:0, others:-1] | 0 already visited |
| 9 | Enqueue neighbor 3 | 1 | [2,3] | {0,1,2,3} | [0:0,1:1,2:1,3:2, others:∞] | [0:-1,1:0,2:0,3:1, others:-1] | Mark 3 visited, distance=2, parent=1 |
| 10 | Dequeue | 2 | [3] | {0,1,2,3} | [0:0,1:1,2:1,3:2, others:∞] | [0:-1,1:0,2:0,3:1, others:-1] | Visit node 2 |
| 11 | Visit neighbors | 2 | [3] | {0,1,2,3} | [0:0,1:1,2:1,3:2, others:∞] | [0:-1,1:0,2:0,3:1, others:-1] | Neighbors of 2: 0, 3, 4 |
| 12 | Skip neighbor 0 (visited) | 2 | [3] | {0,1,2,3} | [0:0,1:1,2:1,3:2, others:∞] | [0:-1,1:0,2:0,3:1, others:-1] | 0 already visited |
| 13 | Skip neighbor 3 (visited) | 2 | [3] | {0,1,2,3} | [0:0,1:1,2:1,3:2, others:∞] | [0:-1,1:0,2:0,3:1, others:-1] | 3 already visited |
| 14 | Enqueue neighbor 4 | 2 | [3,4] | {0,1,2,3,4} | [0:0,1:1,2:1,3:2,4:2, others:∞] | [0:-1,1:0,2:0,3:1,4:2, others:-1] | Mark 4 visited, distance=2, parent=2 |
| 15 | Dequeue | 3 | [4] | {0,1,2,3,4} | [0:0,1:1,2:1,3:2,4:2, others:∞] | [0:-1,1:0,2:0,3:1,4:2, others:-1] | Visit node 3 |
| 16 | Visit neighbors | 3 | [4] | {0,1,2,3,4} | [0:0,1:1,2:1,3:2,4:2, others:∞] | [0:-1,1:0,2:0,3:1,4:2, others:-1] | Neighbors of 3: 1, 2, 5 |
| 17 | Skip neighbor 1 (visited) | 3 | [4] | {0,1,2,3,4} | [0:0,1:1,2:1,3:2,4:2, others:∞] | [0:-1,1:0,2:0,3:1,4:2, others:-1] | 1 already visited |
| 18 | Skip neighbor 2 (visited) | 3 | [4] | {0,1,2,3,4} | [0:0,1:1,2:1,3:2,4:2, others:∞] | [0:-1,1:0,2:0,3:1,4:2, others:-1] | 2 already visited |
| 19 | Enqueue neighbor 5 | 3 | [4,5] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | Mark 5 visited, distance=3, parent=3 |
| 20 | Dequeue | 4 | [5] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | Visit node 4 |
| 21 | Visit neighbors | 4 | [5] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | Neighbors of 4: 2 |
| 22 | Skip neighbor 2 (visited) | 4 | [5] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | 2 already visited |
| 23 | Dequeue | 5 | [] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | Visit node 5 |
| 24 | Visit neighbors | 5 | [] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | Neighbors of 5: 3 |
| 25 | Skip neighbor 3 (visited) | 5 | [] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | 3 already visited |
| 26 | Queue empty | - | [] | {0,1,2,3,4,5} | [0:0,1:1,2:1,3:2,4:2,5:3] | [0:-1,1:0,2:0,3:1,4:2,5:3] | BFS complete, shortest distances and parents set |