1- package com .thealgorithms .graphs ;
1+ package com .thealgorithms .searches ; // update to match path; change back if you intend 'com.thealgorithms.graphs'
22
3- import java .util .*;
3+ import java .util .List ;
4+ import java .util .Arrays ;
5+ import java .util .PriorityQueue ;
6+ import java .util .Comparator ;
47
58/**
69 * Implementation of Dijkstra's Algorithm.
1013 * @date: 19 October 2025 (Sunday)
1114 * @wiki: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
1215 */
13- public class Dijkstras {
16+ public final class Dijkstras {
17+
18+ // Hide utility-class constructor
19+ private Dijkstras () {
20+ throw new AssertionError ("Cannot instantiate utility class" );
21+ }
1422
1523 /**
1624 * Computes the shortest distance from a source vertex to all other vertices.
1725 *
1826 * @param graph adjacency list representing the graph, where graph[u] contains pairs (v, weight)
1927 * @param src the source vertex
20- * @param V total number of vertices
28+ * @param v total number of vertices
2129 * @return an array of shortest distances from src to every vertex
2230 */
23- public static int [] dijkstra (List <List <Node >> graph , int src , int V ) {
24- int [] dist = new int [V ];
31+ public static int [] dijkstra (List <List <Node >> graph , int src , int v ) {
32+ int [] dist = new int [v ];
2533 Arrays .fill (dist , Integer .MAX_VALUE );
2634 dist [src ] = 0 ;
2735
@@ -52,4 +60,4 @@ public Node(int vertex, int weight) {
5260 this .weight = weight ;
5361 }
5462 }
55- }
63+ }
0 commit comments