0
0
DSA Cprogramming~5 mins

Shortest Path in DAG Using Topological Order in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Directed Acyclic Graph (DAG)?
A Directed Acyclic Graph (DAG) is a graph with directed edges and no cycles, meaning you cannot start at one node and follow a path that leads back to the same node.
Click to reveal answer
intermediate
Why do we use topological order for shortest path in a DAG?
Topological order arranges nodes so that all edges go from earlier to later nodes. This order helps us relax edges only once, making shortest path calculation efficient in DAGs.
Click to reveal answer
beginner
What does 'relaxing an edge' mean in shortest path algorithms?
Relaxing an edge means checking if the current known shortest distance to a node can be improved by going through another node connected by that edge, and updating it if yes.
Click to reveal answer
intermediate
What is the time complexity of finding shortest paths in a DAG using topological order?
The time complexity is O(V + E), where V is the number of vertices and E is the number of edges, because each node and edge is processed once.
Click to reveal answer
beginner
In the context of shortest path in DAG, what initial distance values do we assign before processing?
We assign 0 to the source node and infinity (or a very large number) to all other nodes to indicate they are initially unreachable.
Click to reveal answer
What property must a graph have to use topological order for shortest path calculation?
AIt must be a Directed Acyclic Graph (DAG)
BIt must be undirected
CIt must contain cycles
DIt must be a tree
What is the first step in finding shortest paths in a DAG using topological order?
ARelax all edges randomly
BFind the topological order of the graph
CInitialize all distances to zero
DRun Dijkstra's algorithm
When relaxing edges in shortest path for DAG, how many times is each edge relaxed?
AOnce
BMultiple times
CNever
DDepends on the graph size
What initial distance is assigned to the source node before starting the algorithm?
A-1
BInfinity
C0
DNumber of nodes
What happens if the graph contains a cycle when trying to find shortest path using topological order?
AEdges are ignored
BAlgorithm runs normally
CShortest path is found faster
DTopological order does not exist, so the method fails
Explain how topological order helps in finding the shortest path in a DAG.
Think about how ordering nodes prevents revisiting edges multiple times.
You got /4 concepts.
    Describe the steps to find shortest paths in a DAG using topological order starting from a source node.
    Start with distance setup, then order, then edge relaxation.
    You got /5 concepts.