0
0
DSA Cprogramming~5 mins

Dijkstra's Algorithm Single Source Shortest Path in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main goal of Dijkstra's Algorithm?
To find the shortest path from a single starting point (source) to all other points (vertices) in a graph with non-negative edge weights.
Click to reveal answer
intermediate
In Dijkstra's Algorithm, what data structure is commonly used to select the next vertex with the smallest tentative distance?
A priority queue (often implemented as a min-heap) is used to efficiently pick the vertex with the smallest current distance estimate.
Click to reveal answer
intermediate
Why can't Dijkstra's Algorithm handle graphs with negative edge weights?
Because it assumes that once a vertex's shortest distance is found, it won't change. Negative edges can create shorter paths later, breaking this assumption.
Click to reveal answer
advanced
What is the time complexity of Dijkstra's Algorithm using a min-heap and adjacency list?
O((V + E) log V), where V is the number of vertices and E is the number of edges.
Click to reveal answer
beginner
Explain the relaxation step in Dijkstra's Algorithm.
Relaxation means checking if the current known distance to a neighbor can be improved by going through the current vertex. If yes, update the neighbor's distance.
Click to reveal answer
What type of graph edge weights does Dijkstra's Algorithm require?
AAny weights including negative cycles
BNegative weights allowed
COnly zero weights
DNon-negative weights
Which data structure helps efficiently pick the next vertex with the smallest distance in Dijkstra's Algorithm?
APriority queue (min-heap)
BStack
CQueue
DLinked list
What happens during the relaxation step in Dijkstra's Algorithm?
AEdges are reversed
BDistances to neighbors are updated if a shorter path is found
CVertices are removed from the graph
DAll distances are reset to infinity
What is the initial distance to the source vertex in Dijkstra's Algorithm?
AInfinity
BNegative infinity
CZero
DOne
What is the worst-case time complexity of Dijkstra's Algorithm using a simple array instead of a priority queue?
AO(V^2)
BO(E log V)
CO(V + E)
DO(log V)
Describe the main steps of Dijkstra's Algorithm for finding the shortest path from a source vertex.
Think about how distances are updated and how the next vertex is chosen.
You got /5 concepts.
    Explain why Dijkstra's Algorithm does not work with graphs containing negative edge weights.
    Consider what happens if a shorter path appears after a vertex is finalized.
    You got /4 concepts.