Why is time complexity for BFS/DFS not simply O(E) instead of O(E+V)?
问题 I know there's a similar question in stack overflow, where one person has asked, why time complexity of BFS/DFS is not simply O(V). The appropriate answer given was that E can be as large as V^2 in case of complete graph, and hence it is valid to include E in time complexity. But, if V cannot be greater than E+1. So, in that case not having V in the time complexity, should work? 回答1: If it is given that E = kV + c , for some real constants k and c then, O(E + V) = O(kV + c + V) = O(V) = O(E)