Q. How does Dijkstra's algorithm ensure that the shortest path is found?
-
A.
By exploring all possible paths
-
B.
By using a greedy approach
-
C.
By backtracking
-
D.
By using dynamic programming
Solution
Dijkstra's algorithm uses a greedy approach, always expanding the least costly node first, ensuring that the shortest path is found.
Correct Answer:
B
— By using a greedy approach
Learn More →
Q. In Dijkstra's algorithm, what data structure is commonly used to select the next node to process?
-
A.
Stack
-
B.
Queue
-
C.
Priority Queue
-
D.
Array
Solution
A priority queue is used in Dijkstra's algorithm to efficiently select the node with the smallest tentative distance.
Correct Answer:
C
— Priority Queue
Learn More →
Q. In which scenario would you prefer using Dijkstra's algorithm over the Bellman-Ford algorithm?
-
A.
When the graph has negative weights
-
B.
When the graph is dense
-
C.
When the graph has non-negative weights
-
D.
When you need to find all pairs shortest paths
Solution
Dijkstra's algorithm is preferred when the graph has non-negative weights, as it is more efficient in such cases compared to Bellman-Ford.
Correct Answer:
C
— When the graph has non-negative weights
Learn More →
Q. What is the main application of Dijkstra's algorithm in real-world scenarios?
-
A.
Finding the maximum flow in a network
-
B.
Routing in GPS systems
-
C.
Sorting data
-
D.
Searching for an item in a database
Solution
Dijkstra's algorithm is widely used in GPS systems for routing to find the shortest path between locations.
Correct Answer:
B
— Routing in GPS systems
Learn More →
Q. What is the role of the 'visited' set in Dijkstra's algorithm?
-
A.
To keep track of the nodes that have been processed
-
B.
To store the shortest path distances
-
C.
To maintain the priority queue
-
D.
To count the number of edges
Solution
The 'visited' set in Dijkstra's algorithm keeps track of the nodes that have already been processed to avoid reprocessing them.
Correct Answer:
A
— To keep track of the nodes that have been processed
Learn More →
Q. Which of the following algorithms can be used to find the shortest path in a graph with negative weights?
-
A.
Dijkstra's algorithm
-
B.
A* algorithm
-
C.
Bellman-Ford algorithm
-
D.
Depth-first search
Solution
The Bellman-Ford algorithm can handle graphs with negative weights and is used to find the shortest paths in such cases.
Correct Answer:
C
— Bellman-Ford algorithm
Learn More →
Showing 1 to 6 of 6 (1 Pages)