This project implements a shortest path finder algorithm using Dijkstra's algorithm. It finds the shortest path between two nodes in a graph represented as an adjacency list.
This repository contains JavaScript code for finding the shortest path between two nodes in a graph. It includes an implementation of Dijkstra's algorithm and a priority queue data structure used in the algorithm.
- A class representing a priority queue used in Dijkstra's algorithm.
- It supports operations like enqueue, dequeue, siftUp, and siftDown.
- A function that finds the shortest path between two nodes in a graph.
- It takes the start node, end node, and the graph represented as an adjacency list as input.
- Returns the shortest path as an array of nodes.
- A function that reconstructs the shortest path found by
shortestPath
function. - It takes the previous node mapping and the end node as input.
- Returns the shortest path as an array of nodes.
- Clone this repository.
- Open the project directory.
- Run the JavaScript code using Node.js.
const graph = {
'a': { 'b': 1, 'c': 4 },
'b': { 'c': 2, 'd': 5 },
'c': { 'd': 1 },
'd': {}
};
console.log(shortestPath('a', 'd', graph)); // ['a', 'b', 'c', 'd']