Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.backtracking;

import java.util.Arrays;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.bitmanipulation;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

/**
* Generates a crc16 checksum for a given string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import java.util.BitSet;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import java.util.ArrayList;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import java.util.Arrays;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.compression;

import java.util.Comparator;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures;

import java.util.Arrays;
import java.util.LinkedHashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

/**
* Provides a method to perform a left rotation on an array.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

/**
* Provides a method to perform a right rotation on an array.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

/**
* The BFPRT (Median of Medians) algorithm implementation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;
import java.util.Optional;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

import java.util.Arrays;
import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

import java.util.Arrays;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.arrays;

/**
* Utility class for operations to find the range of occurrences of a key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.arrays;

import java.util.Random;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.arrays;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.arrays;

/**
* The two-pointer technique is a useful tool to utilize when searching for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.arrays;

import java.util.HashMap;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.graphs;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -23,19 +23,19 @@ public final class Dijkstra {
private Dijkstra() {
}

private static final Graph.Edge[] GRAPH = {
private static final DijkstraGraph.Edge[] GRAPH = {
// Distance from node "a" to node "b" is 7.
// In the current Graph there is no way to move the other way (e,g, from "b" to "a"),
// a new edge would be needed for that
new Graph.Edge("a", "b", 7),
new Graph.Edge("a", "c", 9),
new Graph.Edge("a", "f", 14),
new Graph.Edge("b", "c", 10),
new Graph.Edge("b", "d", 15),
new Graph.Edge("c", "d", 11),
new Graph.Edge("c", "f", 2),
new Graph.Edge("d", "e", 6),
new Graph.Edge("e", "f", 9),
new DijkstraGraph.Edge("a", "b", 7),
new DijkstraGraph.Edge("a", "c", 9),
new DijkstraGraph.Edge("a", "f", 14),
new DijkstraGraph.Edge("b", "c", 10),
new DijkstraGraph.Edge("b", "d", 15),
new DijkstraGraph.Edge("c", "d", 11),
new DijkstraGraph.Edge("c", "f", 2),
new DijkstraGraph.Edge("d", "e", 6),
new DijkstraGraph.Edge("e", "f", 9),
};
private static final String START = "a";
private static final String END = "e";
Expand All @@ -44,14 +44,18 @@ private Dijkstra() {
* main function Will run the code with "GRAPH" that was defined above.
*/
public static void main(String[] args) {
Graph g = new Graph(GRAPH);
DijkstraGraph g = new DijkstraGraph(GRAPH);
g.dijkstra(START);
g.printPath(END);
// g.printAllPaths();
}
}

class Graph {
/**
* renamed from Graph to DijkstraGraph to prevent name conflict
* with Graph in {@link ConnectedComponent}
* */
class DijkstraGraph {

// mapping of vertex names to Vertex objects, built from a set of Edges

Expand Down Expand Up @@ -152,7 +156,7 @@ public String toString() {
/**
* Builds a graph from a set of edges
*/
Graph(Edge[] edges) {
DijkstraGraph(Edge[] edges) {
graph = new HashMap<>(edges.length);

// one pass to find all vertices
Expand All @@ -167,9 +171,15 @@ public String toString() {

// another pass to set neighbouring vertices
for (Edge e : edges) {
graph.get(e.v1).neighbours.put(graph.get(e.v2), e.dist);
// graph.get(e.v2).neighbours.put(graph.get(e.v1), e.dist); // also do this for an
// undirected graph
var v1 = graph.get(e.v1);
var v2 = graph.get(e.v2);

// this null-check satisfies Infer static analyzer
if (v1 != null && v2 != null) {
v1.neighbours.put(v2, e.dist);
// v2.neighbours.put(v1, e.dist); // also do this for an
// undirected graph
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.graphs;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

import java.util.Collections;
import java.util.PriorityQueue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

public final class MedianOfRunningArrayByte extends MedianOfRunningArray<Byte> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

public final class MedianOfRunningArrayDouble extends MedianOfRunningArray<Double> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

public final class MedianOfRunningArrayFloat extends MedianOfRunningArray<Float> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

public final class MedianOfRunningArrayInteger extends MedianOfRunningArray<Integer> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.datastructures.queues;

public final class MedianOfRunningArrayLong extends MedianOfRunningArray<Long> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.datastructures.queues;

import java.util.Stack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.devutils.generators;

/**
* *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.devutils.generators;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.divideandconquer;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.geometry;

import java.awt.BasicStroke;
import java.awt.Color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.geometry;

import java.util.Arrays;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.geometry;

import java.util.Random;
import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.graph;

import java.util.LinkedList;
import java.util.Queue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.maths;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.maths;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.maths;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.maths;

/**
* Gauss Legendre Algorithm ref
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.maths;

import java.awt.Color;
import java.awt.image.BufferedImage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.matrix;

/**
* Utility class for calculating the sparsity of a matrix.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.memorymanagement;

import java.util.Scanner;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.memorymanagement;

import java.util.ArrayList;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.backtracking;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.checksums;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
Loading
Loading