Let a be the average size of an adjacency list Adj[u].
Let d be the current distance from the start vertex in the search.
When d is: | The size of S is: | |
---|---|---|
0 | 1 | |
1 | a | |
2 | O(a + a) |
At each depth of the search, only the vertices u along the chosen path, and their undiscovered siblings on Adj[u], are stored.