I have a certain problem understanding the complexity of the Djisktra algorithm and hope someone can correct me.
For my example I took a complete graph with n vertices.
You pick a starting vertex, lets say a1, mark it, and then compute all n-1 weights on the edges. O(n)
You pick the smallest one. Let's say vertex a2 and mark it. O(n)
After that you compute n-2 new weights on the edges and look for the next yet unmarked vertex to add your set of marked vertices.
And so on...
The algorithm runs til you could mark all vertices. Complexity: n-1 + n-2 + ... + n - (n - 1) = Binom(n,2) which is in O(n^2), not O(n*ln(n)) what I want.
I read about many many times people use a heap for optimization, however I still don't see how to avoid Binom(n,2) computations.
I have to be wrong at some point, but do not see where.