Java
Java copied to clipboard
Add Dijkstra Algorithm Implementation Using PriorityQueue (Fixes #7112)
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.javainside 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