Module 08 · DSA · Worked problems, in English · about 19 min to read
Continue where you left off ×
Clinic #25: Network Delay Time
Pattern: Graphs / Dijkstra · LC 743
Shortest Path Traced · Open board
Five towns joined by one-way roads, a travel time on every road, and the earliest arrival written beside each town. This clinic uses that same five-point map, drawn as a table of falling dominoes.
Before you start. You need a list, and the habit of keeping a running smallest number while you read it. Dots joined by lines (a graph) are introduced in Graphs (BFS, DFS, Dijkstra, topological sort) , and Shortest Paths, Worked (Dijkstra, Bellman-Ford, A*) traces this same map three ways. Neither is needed first, because everything below is built by hand from one small table.
The idea in 30 seconds
Network Delay Time asks when the last computer hears a signal sent over one-way timed wires: the biggest of every computer’s earliest arrival time, or -1 if one never hears it.
A shortest path is the route with the least total time, and fewest wires is a different question: two short wires can beat one long one.
Dijkstra’s algorithm always handles the earliest pending arrival next, and that arrival is final, because wire times are never negative.
A priority queue hands back its smallest item first, which is exactly the “earliest pending arrival” the algorithm needs.
A computer can collect several guessed arrival times, called promises. The earliest one taken is final, and any later one is stale and gets skipped.
Read the story
Lesson 64 of 96 in DSA
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson May 1979: the ARPANET starts timing its own wires LeetCode 743: the same question, as a list of wires A table of dominoes: the question you can watch The wrong first idea: count the lines A node falls once, at its shortest path time Dijkstra’s algorithm: always handle whichever node falls next The priority queue: a pile that always hands back the earliest Solution ladder The trace, printed Measured: where each one loses The bug that passes the sample Interview path, first time The tell The ladder for this pattern Terms it explains: LC 743, node, edge, shortest path, Dijkstra's algorithm, priority queue, Dijkstra + heap, O(E log n), write this one, plus, Path with Maximum Probability.
Review DSA
Mark as read Saved in this browser, and to your account when you sign in.