Identify the correct Bellmann Ford Algorithm.

Identify the correct Bellmann Ford Algorithm.
A.
Code:
for i=1 to V[g]-1
	do for each edge (u,v) in E[g]
		do Relax(u,v,w)
   for each edge (u,v) in E[g]
	do if d[v]>d[u]+w(u,v)
		then return False
   return True
B.
Code:
for i=1 to V[g]-1
       for each edge (u,v) in E[g]
	do if d[v]>d[u]+w(u,v)
		then return False
    return True
C.
Code:
for i=1 to V[g]-1
	do for each edge (u,v) in E[g]
		do Relax(u,v,w)
   for each edge (u,v) in E[g]
	do if d[v]<d[u]+w(u,v)
		then return true
   return True
D.
Code:
for i=1 to V[g]-1
	do for each edge (u,v) in E[g]
		do Relax(u,v,w)
   return True
[/u][/u][/u]
 
Answer: a
Explanation: After initialization, the algorithm makes v-1 passes over the edges of the graph. Each pass is one iteration of the for loop and consists of relaxing each edge of the graph once. Then it checks for the negative weight cycle and returns an appropriate Boolean value.
 

Tìm kiếm

Back
Top