Let a be the average size of an adjacency list Adj[u].
Let d be the current distance from S in the search.
| When d is: | The size of Q is: | |
|---|---|---|
| 0 | 1 | |
| 1 | a | |
| 2 | O(a × a) |
For each of the a vertices discovered at distance 1, a more vertices at distance 2 are added to the queue.