the complexity of BFS comes from the traversal itself (O(V+E)), you are misleading for that!
@niemasd
8 ай бұрын
The traversal itself is not O(V + E). Imagine you have a complete graph with V-1 nodes (so (V-1)(V-2)/2 edges), and you have a single additional node on its own unattached. BFS starting at that single additional node will finish instantly because it has no outgoing edges. BFS traversal starting from a single vertex is bounded by the edges you are able to traverse, not the number of vertices (there are many vertices you may possibly never be able to encounter if there are no edges connecting to them). The O(V) term comes from initialization (or if you chose to perform repeated BFS traversals to force yourself to explore the whole graph). A single BFS traversal starting from a single node is O(E)
@niemasd
8 ай бұрын
Oh, just realized which video this is in response to LOL so not sure if it was just a meme comment 😂 But figured I'd respond just in case!
Пікірлер: 5