From 5aa05fdf2c2004c75ed1fc5424e4c29554e4d418 Mon Sep 17 00:00:00 2001 From: nikhil kala Date: Wed, 29 Jan 2020 01:50:50 +0530 Subject: [PATCH 1/2] Delete Dijkshtra.java Duplicate and wrongly named. --- Others/Dijkshtra.java | 85 ------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 Others/Dijkshtra.java diff --git a/Others/Dijkshtra.java b/Others/Dijkshtra.java deleted file mode 100644 index d964d0596..000000000 --- a/Others/Dijkshtra.java +++ /dev/null @@ -1,85 +0,0 @@ -package Others; - -import java.util.Arrays; -import java.util.Scanner; -import java.util.Stack; - -/** - * @author Mayank K Jha - */ - -public class Dijkshtra { - - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - - // n = Number of nodes or vertices - int n = in.nextInt(); - // m = Number of Edges - int m = in.nextInt(); - - // Adjacency Matrix - long[][] w = new long[n + 1][n + 1]; - - // Initializing Matrix with Certain Maximum Value for path b/w any two vertices - for (long[] row : w) { - Arrays.fill(row, 1000000L); - } - - /* From above,we Have assumed that,initially path b/w any two Pair of vertices is Infinite such that Infinite = 1000000l - For simplicity , We can also take path Value = Long.MAX_VALUE , but i have taken Max Value = 1000000l */ - - // Taking Input as Edge Location b/w a pair of vertices - for (int i = 0; i < m; i++) { - int x = in.nextInt(), y = in.nextInt(); - long cmp = in.nextLong(); - - // Comparing previous edge value with current value - Cycle Case - if (w[x][y] > cmp) { - w[x][y] = cmp; - w[y][x] = cmp; - } - } - - // Implementing Dijkshtra's Algorithm - Stack t = new Stack<>(); - int src = in.nextInt(); - - for (int i = 1; i <= n; i++) { - if (i != src) { - t.push(i); - } - } - - Stack p = new Stack<>(); - p.push(src); - w[src][src] = 0; - - while (!t.isEmpty()) { - int min = 989997979; - int loc = -1; - - for (int i = 0; i < t.size(); i++) { - w[src][t.elementAt(i)] = Math.min(w[src][t.elementAt(i)], w[src][p.peek()] + w[p.peek()][t.elementAt(i)]); - if (w[src][t.elementAt(i)] <= min) { - min = (int) w[src][t.elementAt(i)]; - loc = i; - } - } - p.push(t.elementAt(loc)); - t.removeElementAt(loc); - } - - // Printing shortest path from the given source src - for (int i = 1; i <= n; i++) { - if (i != src && w[src][i] != 1000000L) { - System.out.print(w[src][i] + " "); - } - // Printing -1 if there is no path b/w given pair of edges - else if (i != src) { - System.out.print("-1" + " "); - } - } - in.close(); - } -} \ No newline at end of file From 1f0f1a3cd9c604c5fad43bd16e708339e399b812 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 28 Jan 2020 20:21:07 +0000 Subject: [PATCH 2/2] updating DIRECTORY.md --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 46a9b06c0..a8052bc88 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -142,7 +142,6 @@ * [CountWords](https://github.com/TheAlgorithms/Java/blob/master/Others/CountWords.java) * [CRC32](https://github.com/TheAlgorithms/Java/blob/master/Others/CRC32.java) * [CRCAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/Others/CRCAlgorithm.java) - * [Dijkshtra](https://github.com/TheAlgorithms/Java/blob/master/Others/Dijkshtra.java) * [Dijkstra](https://github.com/TheAlgorithms/Java/blob/master/Others/Dijkstra.java) * [EulersFunction](https://github.com/TheAlgorithms/Java/blob/master/Others/EulersFunction.java) * [FibToN](https://github.com/TheAlgorithms/Java/blob/master/Others/FibToN.java)