Intuition
BFS dequeues each vertex once and then scans that vertex's adjacency list. In an undirected graph the edge is stored in both 's list and 's list. So while processing you scan it once, and while processing you scan it again: each edge is examined exactly twice.
Result / Method
Summing the scan cost over all vertices gives edge inspections. Adding the cost of enqueueing/dequeueing each vertex once yields the textbook bound: Note alone is wrong: for a connected graph can reach .
Worked example
Graph with edges ():
adj[a] = [b, c]
adj[b] = [a, c]
adj[c] = [a, b]
Edge is seen in adj[a] and in adj[b] -> 2 times. Same for the other two edges. Total scans .
Exam trick: "Vertices are visited in order of smallest distance from " sounds true (BFS is level-order), but the order within a level is arbitrary, so it does not pin down the visiting order. The clean, unambiguous fact is that each undirected edge is scanned exactly twice — the very accounting behind .