Q. If a graph has negative weight edges, which algorithm should be used instead of Dijkstra's?
-
A.
Prim's algorithm
-
B.
Kruskal's algorithm
-
C.
Bellman-Ford algorithm
-
D.
A* algorithm
Solution
The Bellman-Ford algorithm can handle graphs with negative weight edges, unlike Dijkstra's algorithm.
Correct Answer:
C
— Bellman-Ford algorithm
Learn More →
Q. In a graph represented as an adjacency list, what is the space complexity?
-
A.
O(V + E)
-
B.
O(V^2)
-
C.
O(E)
-
D.
O(V)
Solution
The space complexity of a graph represented as an adjacency list is O(V + E), where V is the number of vertices and E is the number of edges.
Correct Answer:
A
— O(V + E)
Learn More →
Q. In which scenario is Dijkstra's algorithm most efficient?
-
A.
When all edge weights are equal
-
B.
When the graph is sparse
-
C.
When the graph is dense
-
D.
When there are many negative weights
Solution
Dijkstra's algorithm is most efficient in sparse graphs where the number of edges is much less than the maximum possible number of edges.
Correct Answer:
B
— When the graph is sparse
Learn More →
Q. Which of the following is a key step in Dijkstra's algorithm?
-
A.
Updating the distance of adjacent vertices
-
B.
Sorting the vertices
-
C.
Removing the vertex from the graph
-
D.
Adding edges to the graph
Solution
A key step in Dijkstra's algorithm is updating the distance of adjacent vertices based on the current vertex's distance.
Correct Answer:
A
— Updating the distance of adjacent vertices
Learn More →
Showing 1 to 4 of 4 (1 Pages)