# What simple arguments and insights can I observe that running both BFS and DFS can be achieved in O(|V| + |E|)?

BFS and DFS can be achieved in O(|V| + |E|). I understand the proof but it seems a bit lengthy.

• Can I argue O(|V| + |E|) in a very simply way? e.g. checking each edge at most once?
• Also what does O(|V| + |E|) imply?

I know Dijstrka algorithm and many other algorithm is somewhat like BFS. Does it imply automatically they can be run in |V| + |E| is the lower bound?

• "I understand the proof but it seems a bit lengthy." -- they aren't. I recommend you spend some time to understand these proofs. Otherwise you'll be completely lost when you enter more complex things. – Raphael Sep 24 '16 at 10:56
• "checking each edge at most once? " -- that's a central part of the proof. – Raphael Sep 24 '16 at 10:56
• "Also what does O(|V| + |E|) imply?" -- unfold the definition; what more are you looking for? – Raphael Sep 24 '16 at 10:56
• "I know Dijstrka algorithm and many other algorithm is somewhat like BFS." -- define "somewhat like". Yes, every algorithm that considers each part of the input has input size as a lower bound on the running time. – Raphael Sep 24 '16 at 10:57
• In total, I'm not sure there really is much of a question here. Community votes, please! – Raphael Sep 24 '16 at 10:58

Intuitively, what a time upper bound of $O(|V| + |E|)$ means is that you spend $O(1)$ time per each vertex and each edge. Taking as an example DFS, there is one recursive call per edge, and the procedure itself runs once per vertex. You can turn this into a full-fledged argument that proves the upper bound.
An upper bound of $O(|V| + |E|)$ is optimal for most graph problems – those that potentially require examining all vertices and all edges. What such an upper bound tells you is that your problem can be solved in the minimal possible time; an $O(|V| + |E|)$ algorithm is an asymptotically optimal algorithm.