raj*_*han 4 algorithm complexity-theory big-o prims-algorithm
我使用的伪代码:
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;
Run Code Online (Sandbox Code Playgroud)
根据我的理解:
V-1次数。2E时间对于每一行 2:第 3 行和第 4 行需要log E时间,因为我们正在PQ逐条添加/删除所有边。
所以总time= V-1+2E.logE=E.log E
但是书上说是的E.logV,你能解释一下这是为什么吗?