Skip to content

Commit c3a52b4

Browse files
authored
Merge pull request kelvins#258 from Abhiharsh-IN/Abhiharsh-IN-Hacktoberfest
Translated Portuguese comments and added English comments alongside i…
2 parents e116f95 + 66774dc commit c3a52b4

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/java/Dijkstra.java

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// Algoritimo de Dijkstra
1+
// Dijkstra's Algorithm
22
// Anderson Carneiro da Silva
33
// https://github.com/AndersonSheep
44

5-
// Baseado no método do GeekforGeeks
6-
// Um programa Java para o algoritmo de caminho mais curto de fonte única de Dijkstra.
7-
// O programa é para representação da matriz de adjacência do grafo
5+
// Based on the GeekforGeeks method
6+
// A Java program for Dijkstra's single-source shortest path algorithm.
7+
// The program is for the representation of the graph's adjacency matrix.
88
import java.io.*;
99
import java.util.*;
1010

1111
class ShortestPath {
12-
// Uma função de utilidade para encontrar o vértice com valor mínimo de distância,
13-
// do conjunto de vértices ainda não incluídos na árvore do caminho mais curto
12+
// A utility function to find the vertex with the minimum distance value,
13+
// from the set of vertices not yet included in the shortest path tree
1414
static final int V = 9;
1515

1616
int minDistance(int dist[], Boolean sptSet[]) {
17-
// Iniciando um valor minimo
17+
// Initialize a minimum value
1818
int min = Integer.MAX_VALUE, min_index = -1;
1919

2020
for (int v = 0; v < V; v++) {
@@ -27,48 +27,48 @@ int minDistance(int dist[], Boolean sptSet[]) {
2727
return min_index;
2828
}
2929

30-
// Uma função de utilidade para imprimir a matriz de distância construída
30+
// A utility function to print the constructed distance matrix
3131
void printSolution(int dist[]) {
3232
System.out.println("Vertex \t\t Distance from Source");
3333
for (int i = 0; i < V; i++) {
3434
System.out.println(i + " \t\t " + dist[i]);
3535
}
3636
}
3737

38-
// Função que implementa o caminho mais curto da fonte única de Dijkstra
39-
// algoritmo para um grafo representado usando matriz de adjacência
38+
// Function that implements Dijkstra's single-source shortest path algorithm
39+
// for a graph represented using an adjacency matrix
4040
void dijkstra(int graph[][], int src) {
41-
// A matriz de saída. dist [i] irá manter a menor distância de src a i
41+
// The output array. dist[i] will hold the shortest distance from src to i
4242
int dist[] = new int[V];
4343

44-
// sptSet [i] será verdadeiro se o vértice i for incluído no mais curto
45-
// árvore do caminho ou distância mais curta de src para i é finalizada
44+
// sptSet[i] will be true if vertex i is included in the shortest
45+
// path tree or the shortest distance from src to i is finalized
4646
Boolean sptSet[] = new Boolean[V];
4747

48-
// Inicializa todas as distâncias como INFINITE e stpSet [] como falso
48+
// Initialize all distances as INFINITE and sptSet[] as false
4949
for (int i = 0; i < V; i++) {
5050
dist[i] = Integer.MAX_VALUE;
5151
sptSet[i] = false;
5252
}
5353

54-
// A distância do vértice de origem é sempre 0
54+
// The distance of the source vertex is always 0
5555
dist[src] = 0;
5656

57-
// Encontre o caminho mais curto para todos os vértices
57+
// Find the shortest path for all vertices
5858
for (int count = 0; count < V - 1; count++) {
59-
// Escolha o vértice de distância mínima do conjunto de vértices
60-
// ainda não processado. vc é sempre igual a src na primeira iteração.
59+
// Pick the vertex with the minimum distance from the set of vertices
60+
// not yet processed. u is always equal to src in the first iteration.
6161
int u = minDistance(dist, sptSet);
6262

63-
// Marque o vértice escolhido como processado
63+
// Mark the chosen vertex as processed
6464
sptSet[u] = true;
6565

66-
// Atualize o valor dist dos vértices adjacentes do vértice escolhido.
66+
// Update the value of dist for the adjacent vertices of the chosen vertex
6767
for (int v = 0; v < V; v++)
6868

69-
// Atualize dist [v] apenas se não estiver em sptSet, há um
70-
// borda de u a v, e peso total do caminho de src a
71-
// v a u é menor que o valor atual de dist [v]
69+
// Update dist[v] only if it's not in sptSet, there is an edge from u to v,
70+
// and the total weight of the path from src to v through u is less than the
71+
// current value of dist[v]
7272
if (!sptSet[v]
7373
&& graph[u][v] != 0
7474
&& dist[u] != Integer.MAX_VALUE
@@ -77,12 +77,12 @@ void dijkstra(int graph[][], int src) {
7777
}
7878
}
7979

80-
// Imprime a matriz de distância construída
80+
// Print the constructed distance matrix
8181
printSolution(dist);
8282
}
8383

8484
public static void main(String[] args) {
85-
// Vamos criar o gráfico de exemplo discutido acima
85+
// Let's create the example graph discussed above
8686
int graph[][] =
8787
new int[][] {
8888
{0, 4, 0, 0, 0, 0, 0, 8, 0},

0 commit comments

Comments
 (0)