Q. In which scenario would you prefer the Bellman-Ford algorithm over Dijkstra's algorithm?
-
A.
When all edge weights are positive
-
B.
When the graph is dense
-
C.
When there are negative weight edges
-
D.
When you need the shortest path in constant time
Solution
You would prefer the Bellman-Ford algorithm when the graph contains negative weight edges, as Dijkstra's algorithm cannot handle them.
Correct Answer:
C
— When there are negative weight edges
Learn More →
Q. What is the main advantage of Dijkstra's algorithm over the Bellman-Ford algorithm?
-
A.
It can handle negative weights
-
B.
It is faster for graphs with non-negative weights
-
C.
It is simpler to implement
-
D.
It can find all pairs shortest paths
Solution
Dijkstra's algorithm is generally faster than the Bellman-Ford algorithm for graphs with non-negative weights.
Correct Answer:
B
— It is faster for graphs with non-negative weights
Learn More →
Q. What is the output of the Bellman-Ford algorithm?
-
A.
A single shortest path
-
B.
A list of all shortest paths from the source
-
C.
The shortest path tree
-
D.
The shortest path length only
Solution
The Bellman-Ford algorithm outputs a list of shortest path distances from the source to all vertices in the graph.
Correct Answer:
B
— A list of all shortest paths from the source
Learn More →
Q. Which algorithm is guaranteed to find the shortest path in a graph with negative weight edges?
-
A.
Dijkstra's algorithm
-
B.
A* algorithm
-
C.
Bellman-Ford algorithm
-
D.
Floyd-Warshall algorithm
Solution
The Bellman-Ford algorithm is guaranteed to find the shortest path in graphs with negative weight edges, unlike Dijkstra's algorithm.
Correct Answer:
C
— Bellman-Ford algorithm
Learn More →
Q. Which of the following statements is true about the Bellman-Ford algorithm?
-
A.
It can handle negative weight edges
-
B.
It is faster than Dijkstra's algorithm for all graphs
-
C.
It only works on directed graphs
-
D.
It cannot detect negative weight cycles
Solution
The Bellman-Ford algorithm can handle graphs with negative weight edges and can also detect negative weight cycles.
Correct Answer:
A
— It can handle negative weight edges
Learn More →
Showing 1 to 5 of 5 (1 Pages)