Given pseudo code of Dijkstra's Algorithm. [code] //Initialise single source(G,s) S=0 Q=V[G] While Q != 0 Do u=extract-min(Q)

Trang Mắm

New member
Given pseudo code of Dijkstra's Algorithm.
Code:
//Initialise single source(G,s)
S=0
Q=V[G]
While Q != 0
    Do u=extract-min(Q)
        S=S union {u}
	    For each vertex v in adj[u]
	        Do relax(u,v,w)
What happens when "While Q != 0" is changed to "while Q>1"?
A. While loop gets executed for v times
B. While loop gets executed for v-1 times
C. While loop gets executed only once
D. While loop does not get executed[/u]
 
Answer: b
Explanation: In the normal execution of Dijkstra's Algorithm, the while loop gets executed V times. The change in the while loop statement causes it to execute only V - 1 times.
 

Tìm kiếm

Back
Top