Breadth-first search from 0. A queue holds the frontier. Take the vertex that has waited longest, look at its neighbours, and enqueue the ones never seen before with their distance. Because of the queue, vertices come out in order of distance from the start.
Breadth-first search from vertex 0 with a queue.
Dequeue 0, distance 0. Its adjacency list: 1, 2. New: 1, 2, each at distance 1, enqueued.
Vertex 0 is dequeued at distance 0. New neighbours 1, 2 are enqueued.
Dequeue 1, distance 1. Its adjacency list: 0, 3. New: 3, each at distance 2, enqueued. Already seen: 0.
Vertex 1 is dequeued at distance 1. New neighbours 3 are enqueued.
Dequeue 2, distance 1. Its adjacency list: 0, 3, 5. New: 5, each at distance 2, enqueued. Already seen: 0, 3.
Vertex 2 is dequeued at distance 1. New neighbours 5 are enqueued.
Dequeue 3, distance 2. Its adjacency list: 1, 2, 4. New: 4, each at distance 3, enqueued. Already seen: 1, 2.
Vertex 3 is dequeued at distance 2. New neighbours 4 are enqueued.
Dequeue 5, distance 2. Its adjacency list: 2, 4. Every neighbour was already seen, so nothing joins the queue.
Vertex 5 is dequeued at distance 2. No new neighbours.
Dequeue 4, distance 3. Its adjacency list: 3, 5. Every neighbour was already seen, so nothing joins the queue.
Vertex 4 is dequeued at distance 3. No new neighbours.
Visited in order 0, 1, 2, 3, 5, 4. The number on each vertex is its distance from 0, and the highlighted edges are the shortest paths back to it. Every vertex was reached. Each vertex was enqueued once and each edge looked at twice: O(V + E).
Breadth-first search visited 0, 1, 2, 3, 5, 4.