Shortest Path in DAG Using Topological Order
📖 Scenario: You are working on a project to find the shortest travel time between cities connected by one-way roads. The roads form a network without any loops, so the map is a Directed Acyclic Graph (DAG). You want to find the quickest route from the starting city to all other cities.
🎯 Goal: Build a TypeScript program that finds the shortest path distances from a starting city to all other cities in a DAG using topological order.
📋 What You'll Learn
Create a graph as an adjacency list with exact edges and weights
Create a variable for the number of cities
Implement topological sorting using DFS
Calculate shortest paths using the topological order
Print the shortest distances array
💡 Why This Matters
🌍 Real World
Finding shortest paths in a DAG is useful in project scheduling, task ordering, and routing where cycles do not exist.
💼 Career
Understanding shortest path algorithms and topological sorting is important for software engineers working on compilers, network routing, and dependency resolution.
Progress0 / 4 steps