When doing Big-O analysis on graph algorithms it usually makes sense to include both the number of Edges and the number of Vertices as relevant variables in the expression, unless you know the graph is such that the number of Vertices dominates the number of Edges (or vice-versa). So usually you don't want to say that an algorithm that has a Big-O complexity of O(E+V)
can be reduced to O(n)
(again, unless either E >> V or V >> E).
That said, as others have pointed out in comments, Djikstra's algorithm does something different than a Breadth First Search algorithm in case the graph is weighted so it only makes sense to compare them when applying to unweighted graphs.
Also, it was pointed out in the comments that O(n)
dominates O(n*logn)
for big values of n
. This means that as n
gets large, n*logn
will always be larger than n
. This can be studied by taking the limit as n approaches infinity of n / (n*logn)
and observing that the limit is 0
which means that the denominator dominates the numerator asymptotically.
The complication in the case of graphs is that you are not comparing f(n)
and g(n)
, but almost always it's going to be f(E,V)
and g(E,V)
so, in your case you are looking at: O(V+E)
and O(V*logV + E)
. Luckily, this is a pretty easy case because the two expressions are almost the same, except for the logV
factor. Since the E
term is common on both sides, you are really just looking at the same O(V * logV)
versus O(V)
comparison discussed above. But things would get messier if you had to compare an algorithm with complexity O(V * logE + E)
against another with complexity O(E * logV)