Java icon indicating copy to clipboard operation
Java copied to clipboard

Add Dijkstra Algorithm Implementation Using PriorityQueue (Fixes #7112)

Open prasanth-30011 opened this issue 2 weeks ago • 1 comments

Summary

This Pull Request adds a clean and efficient implementation of Dijkstra’s Algorithm using a PriorityQueue, as requested in issue #7112.

What This PR Includes

  • New file Dijkstra.java inside the appropriate package.
  • Implementation of Dijkstra’s shortest-path algorithm using:
    • Adjacency list representation
    • Min-heap (PriorityQueue)
  • Detection and handling of negative weighted edges (throws exception, as required).
  • Code follows the structure, style, and formatting used throughout the TheAlgorithms/Java repository.

Why This Change Is Needed

The project did not previously include a fully correct and optimized Dijkstra implementation using a PriorityQueue.
This PR fills that gap and matches the algorithm request posted under issue #7112.

Related Issue

Fixes #7112

prasanth-30011 avatar Nov 25 '25 18:11 prasanth-30011