No , O (|V| + |E|) not equivalent to O (|V|^2) . That's why.
Basically, if O (V + E) is linear time, such that V + E = n, will not O (V ^ 2) also be linear time?
Perhaps this assumes that the graph is somehow explicitly set, we should get it as input in order to be able to work with it, and the total size of the input edges is O (|V| + |E|) = n .
But we do not always have to get input once, and then run the algorithm once. In some cases, we get an input graph, and then run the algorithm many times, so we are interested in its complexity, regardless of the size of the input. In some other cases, the schedule is set implicitly, so the input does not take much time.
Example : consider a knight’s graph on the chessboard k * k : a graph where the vertices are the squares of the chessboard and the edges are knightly movements. An example is the following task: given two squares, find the path of the knights between them, which is the shortest number of moves. The obvious algorithm for solving the problem is a breadth-first search , which takes O (|V| + |E|) time (we can do better, but this is not relevant.)
Here, the input has size O (1) : this is only the size of the board, k and the coordinates of two squares on it. We do not need to read or explicitly plot the chart at any time: it is specified implicitly by size k . At each vertex, we can list all (up to 8) edges from this vertex to O (1) . In terms of k , |V| = O (k) |V| = O (k) , |E| <= 8 k |E| <= 8 k so |E| = O (k) |E| = O (k) , so we also have O (|V| + |E|) = O (k) . On the other hand, O (|V|^2) = O (k^2) , which is a looser estimate than O (k) .
Therefore, in this example, O (|V| + |E|) is different from O (|V|^2) , so they are usually not equivalent.