Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.36 KB

README.md

File metadata and controls

40 lines (29 loc) · 1.36 KB

Shortest Path Finder

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.

Description:

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.

Classes:

PriorityQueue:

  • A class representing a priority queue used in Dijkstra's algorithm.
  • It supports operations like enqueue, dequeue, siftUp, and siftDown.

shortestPath Function:

  • 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.

reconstructPath Function:

  • 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.

Usage:

  1. Clone this repository.
  2. Open the project directory.
  3. Run the JavaScript code using Node.js.

Example:

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']