I found the time complexity of Prims algorithm everywhere as O((V + E) log V) = E log V. But as we can see the algorithm:

It seems like the time complexity is O(V(log V + E log V)). But if its time complexity is O((V + E) log V). Then the nesting must have to be like this:

But the above nesting is seems to be wrong.
Using a Binary Heap
The time complexity required for one call to
EXTRACT-MIN(Q)isO(log V)using a min priority queue. The while loop at line 6 is executing total V times.soEXTRACT-MIN(Q)is calledVtimes. So the complexity ofEXTRACT-MIN(Q)isO(V logV).The
forloop at line 8 is executing total2Etimes as length of each adjacency lists is2Efor an undirected graph. The time required to execute line 11 isO(log v)by using theDECREASE_KEYoperation on the min heap. Line 11 also executes total2Etimes. So the total time required to execute line 11 isO(2E logV) = O(E logV).The
forloop at line 1 will be executedVtimes. Using the procedure to perform lines 1 to 5 will require a complexity ofO(V).Total time complexity of
MST-PRIMis the sum of the time complexity required to execute steps 1 through 3 for a total ofO((VlogV) + (E logV) + (V)) = O(E logV)since|E| >= |V|.Using a Fibonacci Heap
O(1)amortized time. Line 11 executes a total of2Etimes. So the total time complexity isO(E).So the total time complexity of
MST-PRIMis the sum of executing steps 1 through 3 for a total complexity ofO(V logV + E + V)=O(E + V logV).