If we suppose that the implementation of the digraph uses objects for vertices and each vertex has an associated list of successors and no additional data structures, then it will be impossible to iterate the edges directly.
If the digraph is connected, then each vertext has at least one associated edge. This means that iteration over the edges via iteration over the vertices takes O(|E|)
time - the iteration over the vertices does not increase the running time, which is dominated by the number of edges.
If the digraph is not connected, then the iteration over the vertices is not necessarily dominated by the number of edges; even isolated vertices have to be processed just to find out that they have no associated outgoing arcs, which can be done in O(|V|+|E|)
time.
In total, the runtime bound of O(|V|+|E|)
is correct in either case; however, for a connected digraph (or an implementation which permits direct iteration over the edges regardless of the number of vertices) one can obtain a tighter runtime bound of O(|E|)
.