Skip to content

Implementation of Dijkstra's algorithm that returns a shortest path tree

License

Notifications You must be signed in to change notification settings

assertis/dijkstra-tree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dijkstra-tree

Implementation of Dijkstra's algorithm that returns a shortest path tree instead of a path between two nodes.

Install

npm install --save dijkstra-tree

Usage

import {DijkstraTree} from "../src";

const graph = [
  { origin: "A", destination: "B", distance: 10 },
  { origin: "B", destination: "C", distance: 10 },
  { origin: "B", destination: "C", distance: 5 },
  { origin: "C", destination: "D", distance: 11 },
];

const algorithm = new DijkstraTree(graph);
const result = algorithm.getTree("A");

console.log(result);
// {
//   "A": {distance: 0, path: ['A']},
//   "B": {distance: 10, path: ['A', 'B']},
//   "C": {distance: 15, path: ['A', 'B', 'C'],
//   "D": {distance: 26, path: ['A', 'B', 'C', 'D']}
// };

Testing

npm test

Contributing

Issues, PRs and contributions are welcome. Please ensure any changes have an accompanying test.

About

Implementation of Dijkstra's algorithm that returns a shortest path tree

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%