Introduction
Network Delay Time is one of the most popular applications of Dijkstra Algorithm.
You are given:
times[][]n
k
Where:
u → vtakes w timeGoal:
Find minimum time for signal from node k to reach all nodes. If any node cannot be reached:
Return -1Example
Input:
times = [[2,1,1],[2,3,1],[3,4,1]] n = 4k = 2
Output:
2Key Observation
We need:
Shortest Distance from Source k to Every Node This is exactly:
Dijkstra Algorithm Algorithm
1. Build graph2. Start from node k
3. Run Dijkstra
4. Find maximum distance
5. Return answer
Dry Run
Source:
2 Distances:
1 = 1
2 = 0
3 = 14 = 2
Maximum:
2 Answer:
2 Approach : Dijkstra Algorithm
Explanation
- Start from source node.
- Use min heap.
- Always process smallest distance node.
- Relax neighbors.
- Track shortest distances.
- Return maximum shortest distance.
Practice
Complexity Analysis
Time Complexity: O((V + E) log V)Space Complexity: O(V + E)Why This Problem is Important
- Dijkstra Algorithm
- Priority Queue
- Shortest Path
- Graph Traversal
- Network Routing
Common Beginner Mistakes
- Returning minimum distance instead of maximum
- Forgetting unreachable nodes
- Using BFS instead of Dijkstra
- Not relaxing edges correctly
- Wrong graph construction
Interview Tip
Always explain:
Run Dijkstra then returnmaximum shortest distance.Related Questions
- Dijkstra Algorithm
- Cheapest Flights Within K Stops
- Path With Minimum Effort
- Swim In Rising Water
Final Takeaway
Network Delay Time is a classic Dijkstra problem.
It teaches:
- Shortest Path Computation
- Priority Queue Usage
- Graph Traversal
- Network Routing Concepts
Mastering Network Delay Time makes advanced shortest path problems significantly easier.