You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-18Lines changed: 13 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,12 @@
3
3
A fast and memory-efficient implementation of Dijkstra's shortest-path algorithm
4
4
for Deno.
5
5
6
-
If you ever run into a problem that can be represented as a graph where the
7
-
solution has something to do with finding the shortest path between nodes, this
8
-
algorithm is nothing short of magical. It is well worth the time to learn how to
9
-
use it, even if you don't really understand how the algorithm works.
10
-
11
6
This implementation of Dijkstra'a algorithm is able to process large in-memory
12
-
graphs. It will perform reasonably well even when the number of edges is in the
13
-
millions. The performance is `O(n*log(n))`, where `n` is proportional to the
14
-
number of nodes plus the number of edges in the graph.
7
+
graphs. It will perform reasonably well even with millions of edges. The
8
+
performance is `O(n*log(n))`, where `n` is proportional to the number of nodes
9
+
plus the number of edges in the graph. The use of integers to represent nodes in
10
+
the graph is intentional and actually one of the keys to its performance and
11
+
scalability.
15
12
16
13
This code was adapted to Typescript from
17
14
[A Walkthrough of Dijkstra's Algorithm (In JavaScript!)](https://medium.com/@adriennetjohnson/a-walkthrough-of-dijkstras-algorithm-in-javascript-e94b74192026)
@@ -37,17 +34,15 @@ deno test --reload
37
34
38
35
# Usage Hints
39
36
40
-
Dijkstra's algorithm actually calculates the shortest paths from the start node
41
-
to every other node in the graph. In other words, it isn't just calculating one
42
-
path at a time. This can let you cheaply do things like find the 20 closest
43
-
nodes from a particular node in the graph, for example.
44
-
45
-
You can reverse the direction of the calculation. Calling it "start node" is
46
-
just a convention. It can also be an end node if you set up the graph correctly.
37
+
Dijkstra's algorithm calculates the shortest _paths_ from the start node to
38
+
_all_ other nodes in the graph. All of them. In other words, it isn't just
39
+
calculating one path at a time. This can let you cheaply do things like find the
40
+
20 closest nodes from a particular node in the graph, for example.
47
41
48
-
This implementation supports cloning the solver and extending its graph
49
-
dynamically. Graph generation can be expensive. For many cases, most of the
50
-
graph can be reused, with a only a small portion needing to be dynamic.
42
+
One you have loaded a graph definition into a solver, you can clone it. You can
43
+
then add nodes to the cloned graph. Loading a large graph over and over takes
44
+
time, and depending on overhead, this can be even slower than calculating the
45
+
shortest paths. This type of reuse lets you get super-fast results.
0 commit comments