The answer is, they are both. Because everything depends on how you are analyzing things.
The questions you should ask yourself are, what am I going through? How big is the tree that forms the algorithm? I know how big it is? For the algorithm at some point?
To traverse the entire graph I must go through all the nodes passing through all the axes (in the worst case we have n2
axes, with n
the number of nodes).
Now, BFS forms a tree, assuming that the number of axes per nodes is x
and x
is maximum, to go from one level to another of the tree I go through x-1
axes for each node of the level.
Well, if I'm node v
and I get to it using the axis (u,v)
I will not go back that axis (I'll ignore it). That is, when you reach the leaves of the tree you will have traveled xn
axes, where n
is the distance from the leaves to the root.
Let's see that this is fulfilled in a finite and complete graph (that of n2
axes).
From the root to the next level the algorithm will run n
axes.
Then in the next level, which has n
nodes, it will travel n-1
axes per level node, that is, it will travel (n-1)*n
axes.
That is, in total n+(n-1)*n
. Which gives n2
.