Pseudo code which i used:
for all V vertices: visited[n]=0
pick any vertex r from graph and set visited[r]=1
For all edges e incident to r
PQ.insert()
while(PQ is not empty)//line 1
f=PQ.min()//f(r,s) is such that visited[s]=0
for all edges e(s,t) incident to s//line 2
if(visited[t]==0)
PQ.insert(e);//line 3
else
PQ.delete(e);//line 4
visited[s]=1;
end while;
According to my understanding,
line 1 executes V-1 times.
Line 2 : Sum of Degree of all the vertices times…..that is 2E times
For each line 2: Line 3 and line 4 take log E time because we’re adding/deleting all the edges to/from the PQ one by one.
So total time= V-1+2E.logE = E.log E
But books say it is E.logV
How??? Please help.
Sorry if it sounds silly :(