DSA_Code icon indicating copy to clipboard operation
DSA_Code copied to clipboard

Implement Dijkstra’s Algorithm (Shortest Path) in Java using Priority Queue

Open REVANTSINGH01 opened this issue 1 year ago • 2 comments

Algorithm Name

Dijkstra Algorithm

Programming Language

Java

Category

Graph Algorithms

Difficulty Level

Medium (Intermediate)

Algorithm Description

Problem Statement

Implement Dijkstra’s Algorithm to find the shortest path from a single source vertex to all other vertices in a weighted graph (non-negative edge weights) using a priority queue (min-heap) for optimization.

Requirements

Programming Language: Java

Folder: algorithms/graph_algorithms

Input:

Number of vertices: V

Number of edges :E

Edges with weights (u, v, w)

Starting vertex :s

Tasks

Implement Dijkstra’s Algorithm using priority queue (min-heap) to select the next vertex efficiently.

Represent the graph using an adjacency list.

Include time complexity (O((V+E) log V)) and space complexity in comments.

Add clear inline comments explaining each step of the algorithm.

Include sample test cases for:

Small connected graph

Graph with multiple paths

Single-node graph

Additional Notes

Negative edge weights are not supported (Dijkstra assumes non-negative edges).

Follow the repo’s folder and naming conventions.

Ensure code compiles successfully and passes any CI tests.

References (Optional)

https://www.geeksforgeeks.org/problems/implementing-dijkstra-set-1-adjacency-matrix/1

Contribution Intent

  • [x] I would like to implement this algorithm myself
  • [ ] I'm requesting this for someone else to implement
  • [ ] I need help implementing this algorithm

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

REVANTSINGH01 avatar Oct 04 '25 13:10 REVANTSINGH01

@Karanjot786 please assign me this issue.

REVANTSINGH01 avatar Oct 04 '25 13:10 REVANTSINGH01

@Pradeepsingh61 if this issue is not resolved can u please assign this issue to me and add hacktoberfest2025 label too

Nitin-0017 avatar Oct 30 '25 05:10 Nitin-0017