This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Bellman-Ford Algorithm”.
1. The Bellmann Ford algorithm returns _______ value.
Explanation: The Bellmann Ford algorithm returns Boolean value whether there is a negative weight cycle that is reachable from the source.
2. Bellmann ford algorithm provides solution for ____________ problems.
a) All pair shortest path
c) Network flow
d) Single source shortest path
Explanation: Bellmann ford algorithm is used for finding solutions for single source shortest path problems. If the graph has no negative cycles that are reachable from the source then the algorithm produces the shortest paths and their weights.
3. Bellmann Ford algorithm is used to indicate whether the graph has negative weight cycles or not.
Explanation: Bellmann Ford algorithm returns true if the graph does not have any negative weight cycles and returns false when the graph has negative weight cycles.
4. How many solution/solutions are available for a graph having negative weight cycle?
a) One solution
b) Two solutions
c) No solution
d) Infinite solutions
Explanation: If the graph has any negative weight cycle then the algorithm indicates that no solution exists for that graph.
5. What is the running time of Bellmann Ford Algorithm?
Explanation: Bellmann Ford algorithm runs in time O(VE), since the initialization takes O(V) for each of V-1 passes and the for loop in the algorithm takes O(E) time. Hence the total time taken by the algorithm is O(VE).
6. How many times the for loop in the Bellmann Ford Algorithm gets executed?
a) V times
Explanation: The for loop in the Bellmann Ford Algorithm gets executed for V-1 times. After making V-1 passes, the algorithm checks for a negative weight cycle and returns appropriate boolean value.
7. Dijikstra’s Algorithm is more efficient than Bellmann Ford Algorithm.
Explanation: The running time of Bellmann Ford Algorithm is O(VE) whereas Dijikstra’s Algorithm has running time of only O(V2).
8. Identify the correct Bellmann Ford Algorithm.
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
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
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
for i=1 to V[g]-1 do for each edge (u,v) in E[g] do Relax(u,v,w) return True
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.
9. What is the basic principle behind Bellmann Ford Algorithm?
Explanation: Relaxation methods which are also called as iterative methods in which an approximation to the correct distance is replaced progressively by more accurate values till an optimum solution is found.
10. Bellmann Ford Algorithm can be applied for _____________
a) Undirected and weighted graphs
b) Undirected and unweighted graphs
c) Directed and weighted graphs
d) All directed graphs
Explanation: Bellmann Ford Algorithm can be applied for all directed and weighted graphs. The weight function in the graph may either be positive or negative.
11. Bellmann Ford algorithm was first proposed by ________
a) Richard Bellmann
b) Alfonso Shimbe
c) Lester Ford Jr
d) Edward F. Moore
Explanation: Alfonso Shimbe proposed Bellmann Ford algorithm in the year 1955. Later it was published by Richard Bellmann in 1957 and Lester Ford Jr in the year 1956. Hence it is called Bellmann Ford Algorithm.
Explanation: The minimum cost to travel from node A to node C is 2.
Hence the total cost is 2.
Explanation: The minimum cost taken by the path a-d-b-c-e-f is 4.
c-e, cost= 2
Hence the total cost is 4.
14. Bellmann Ford Algorithm is an example for ____________
a) Dynamic Programming
b) Greedy Algorithms
c) Linear Programming
d) Branch and Bound
Explanation: In Bellmann Ford Algorithm the shortest paths are calculated in bottom up manner which is similar to other dynamic programming problems.
15. A graph is said to have a negative weight cycle when?
a) The graph has 1 negative weighted edge
b) The graph has a cycle
c) The total weight of the graph is negative
d) The graph has 1 or more negative weighted edges
Explanation: When the total weight of the graph sums up to a negative number then the graph is said to have a negative weight cycle. Bellmann Ford Algorithm provides no solution for such graphs.
Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.
To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.