BigO is used for estimating how much <time, memory, whatever resource>
you will use based on the input size.
When you're building adjacency list you know number of vertex V
and number of edges E
. Now you want to estimate how much memory you need.
O(V+E)
can be interpreted as V > E ? O(V) : O(E)
what means: it'll be linearly complex to max(V,E)
.
You create a list for each v, so you use O(V)
memory on it.
You mark each edge and this uses O(E)
memory. O(V+E)
means exactly that. If you would say that the complexity is O(V^2)
it would mean that for an empty graph with 2*n
vertex you should use approx. 4
time more memory than for an empty graph with n
vertex.
When doing some research on complexity you can test different approach:
- Worst case,
- Average case,
- Best case.
Read about different approaches to the topic and comment if you wish to receive some more information.
EDIT
According to the formal definition, O(V+E)
, O(V^2)
, O(V^3)
and O(V^V^V)
are still correct. In BigO
we try to find the function which grows slowest but still is BigO
with your complexity.