From 1a686c48cf1867c0cb65e84c56f56aa91068bf98 Mon Sep 17 00:00:00 2001
From: Nabila Currently, the class supports temperature conversions between several scales:
- * Celsius, Fahrenheit, Kelvin, Réaumur, Delisle, and Rankine.
- *
- * This class makes use of an {@link UnitsConverter} that handles the conversion logic
- * based on predefined affine transformations. These transformations include scaling factors
- * and offsets for temperature conversions.
- *
- * The {@code UnitsConverter} allows converting values between different units using
- * pre-defined affine conversion formulas. Each conversion is represented by an
- * {@link AffineConverter} that defines the scaling and offset for the conversion.
- *
- * For each unit, both direct conversions (e.g., Celsius to Fahrenheit) and inverse
- * conversions (e.g., Fahrenheit to Celsius) are generated automatically. It also computes
- * transitive conversions (e.g., Celsius to Kelvin via Fahrenheit if both conversions exist).
- *
- * Key features include:
- * Accepts a map of basic conversions and automatically generates inverse and
- * transitive conversions.
- *
- * @param basicConversions the initial set of unit conversions to add.
- */
- public UnitsConverter(final MapExample Usage
- *
- * double result = UnitConversions.TEMPERATURE.convert("Celsius", "Fahrenheit", 100.0);
- * // Output: 212.0 (Celsius to Fahrenheit conversion of 100°C)
- *
- *
- * Temperature Scales Supported
- *
- *
*/
public final class UnitConversions {
- private UnitConversions() {
+
+ /**
+ * Enum managing supported temperature scales to eliminate magic strings
+ * and enforce structural type safety internally.
+ */
+ private enum TemperatureScale {
+ CELSIUS("Celsius"),
+ FAHRENHEIT("Fahrenheit"),
+ KELVIN("Kelvin"),
+ REAUMUR("Réaumur"),
+ DELISLE("Delisle"),
+ RANKINE("Rankine");
+
+ private final String unitName;
+
+ TemperatureScale(String unitName) {
+ this.unitName = unitName;
+ }
+
+ public String getName() {
+ return unitName;
+ }
}
+ // Mathematical Constants for Conversions (Eliminating Magic Numbers)
+ private static final double ABSOLUTE_ZERO_CELSIUS = -273.15;
+
+ private static final double CELSIUS_TO_FAHRENHEIT_SCALE = 9.0 / 5.0;
+ private static final double CELSIUS_TO_FAHRENHEIT_OFFSET = 32.0;
+
+ private static final double REAUMUR_TO_CELSIUS_SCALE = 5.0 / 4.0;
+
+ private static final double DELISLE_TO_CELSIUS_SCALE = -2.0 / 3.0;
+ private static final double DELISLE_TO_CELSIUS_OFFSET = 100.0;
+
+ private static final double RANKINE_TO_KELVIN_SCALE = 5.0 / 9.0;
+
/**
- * A preconfigured instance of {@link UnitsConverter} for temperature conversions.
- * The converter handles conversions between the following temperature units:
- *
- *
+ * Preconfigured instance of UnitsConverter for temperature conversions.
*/
- public static final UnitsConverter TEMPERATURE = new UnitsConverter(Map.ofEntries(entry(Pair.of("Kelvin", "Celsius"), new AffineConverter(1.0, -273.15)), entry(Pair.of("Celsius", "Fahrenheit"), new AffineConverter(9.0 / 5.0, 32.0)),
- entry(Pair.of("Réaumur", "Celsius"), new AffineConverter(5.0 / 4.0, 0.0)), entry(Pair.of("Delisle", "Celsius"), new AffineConverter(-2.0 / 3.0, 100.0)), entry(Pair.of("Rankine", "Kelvin"), new AffineConverter(5.0 / 9.0, 0.0))));
-}
+ public static final UnitsConverter TEMPERATURE = new UnitsConverter(Map.ofEntries(
+ entry(
+ new UnitPair(TemperatureScale.KELVIN.getName(), TemperatureScale.CELSIUS.getName()),
+ new AffineConverter(1.0, ABSOLUTE_ZERO_CELSIUS)
+ ),
+ entry(
+ new UnitPair(TemperatureScale.CELSIUS.getName(), TemperatureScale.FAHRENHEIT.getName()),
+ new AffineConverter(CELSIUS_TO_FAHRENHEIT_SCALE, CELSIUS_TO_FAHRENHEIT_OFFSET)
+ ),
+ entry(
+ new UnitPair(TemperatureScale.REAUMUR.getName(), TemperatureScale.CELSIUS.getName()),
+ new AffineConverter(REAUMUR_TO_CELSIUS_SCALE, 0.0)
+ ),
+ entry(
+ new UnitPair(TemperatureScale.DELISLE.getName(), TemperatureScale.CELSIUS.getName()),
+ new AffineConverter(DELISLE_TO_CELSIUS_SCALE, DELISLE_TO_CELSIUS_OFFSET)
+ ),
+ entry(
+ new UnitPair(TemperatureScale.RANKINE.getName(), TemperatureScale.KELVIN.getName()),
+ new AffineConverter(RANKINE_TO_KELVIN_SCALE, 0.0)
+ )
+ ));
+
+ private UnitConversions() {
+ // Prevent instantiation
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/thealgorithms/conversions/UnitsConverter.java b/src/main/java/com/thealgorithms/conversions/UnitsConverter.java
index 00690b2c0f9b..c64053a81835 100644
--- a/src/main/java/com/thealgorithms/conversions/UnitsConverter.java
+++ b/src/main/java/com/thealgorithms/conversions/UnitsConverter.java
@@ -4,144 +4,161 @@
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Set;
-import org.apache.commons.lang3.tuple.Pair;
/**
- * A class that handles unit conversions using affine transformations.
- *
- *
- *
- *
- * Example Usage
- *
- * Map<Pair<String, String>, AffineConverter> basicConversions = Map.ofEntries(
- * entry(Pair.of("Celsius", "Fahrenheit"), new AffineConverter(9.0 / 5.0, 32.0)),
- * entry(Pair.of("Kelvin", "Celsius"), new AffineConverter(1.0, -273.15))
- * );
- *
- * UnitsConverter converter = new UnitsConverter(basicConversions);
- * double result = converter.convert("Celsius", "Fahrenheit", 100.0);
- * // Output: 212.0 (Celsius to Fahrenheit conversion of 100°C)
- *
- *
- * Exception Handling
- *
- *
+ * Represents a directed conversion between two units using an affine transformation.
*/
-public final class UnitsConverter {
- private final Map> tree;
- private int[] parent;
- private int[] depth;
- private int[] subtreeSize;
- private int[] chainHead;
- private int[] position;
- private int[] nodeValue;
- private int[] segmentTree;
+ private final List
> tree;
+ private final int[] parent;
+ private final int[] depth;
+ private final int[] subtreeSize;
+ private final int[] chainHead;
+ private final int[] position;
+ private final int[] nodeValue;
+ private final int[] segmentTree;
private int positionIndex;
public HeavyLightDecomposition(int n) {
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java b/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
index 5190e82f74ef..02ff8a5ebdaa 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
@@ -142,7 +142,7 @@ public static int comparableDistanceExceptAxis(Point p1, Point p2, int axis) {
static class Node {
private Point point;
- private int axis; // 0 for x, 1 for y, 2 for z, etc.
+ private final int axis; // 0 for x, 1 for y, 2 for z, etc.
private Node left = null; // Left child
private Node right = null; // Right child
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java b/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
index e0d255b1e784..7652d2197eb8 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
@@ -69,7 +69,7 @@ public class QuadTree {
private final BoundingBox boundary;
private final int capacity;
- private List
> adjacencyList;
+ private final List
> adjacencyList;
public Graph(int numNodes) {
adjacencyList = new ArrayList<>();
@@ -61,8 +61,8 @@ public record Edge(int from, int to, int cost, int resource) {
}
}
- private Graph graph;
- private int maxResource;
+ private final Graph graph;
+ private final int maxResource;
/**
* Constructs a CSPSolver with the given graph and maximum resource constraint.
diff --git a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
index ba75b2f4b1b8..1979bbc707c8 100644
--- a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
+++ b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
@@ -8,10 +8,6 @@
/**
* Finds the strongly connected components in a directed graph.
- *
- * @param adjList The adjacency list representation of the graph.
- * @param n The number of nodes in the graph.
- * @return The number of strongly connected components.
*/
public class StronglyConnectedComponentOptimized {
diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java
index 84fc67159379..c588992e3259 100644
--- a/src/main/java/com/thealgorithms/maths/Area.java
+++ b/src/main/java/com/thealgorithms/maths/Area.java
@@ -21,6 +21,12 @@ private Area() {
* String of IllegalArgumentException for base
*/
private static final String POSITIVE_BASE = "Base must be greater than 0";
+ private static final String POSITIVE_SIDE_LENGTH = "Side length must be greater than 0";
+ private static final String POSITIVE_LENGTH = "Length must be greater than 0";
+ private static final String POSITIVE_WIDTH = "Width must be greater than 0";
+ private static final String POSITIVE_SLANT_HEIGHT = "Slant height must be greater than 0";
+ private static final String POSITIVE_BASE_1 = "First base must be greater than 0";
+ private static final String POSITIVE_BASE_2 = "Second base must be greater than 0";
/**
* Calculate the surface area of a cube.
@@ -30,7 +36,7 @@ private Area() {
*/
public static double surfaceAreaCube(final double sideLength) {
if (sideLength <= 0) {
- throw new IllegalArgumentException("Side length must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_SIDE_LENGTH);
}
return 6 * sideLength * sideLength;
}
@@ -43,15 +49,15 @@ public static double surfaceAreaCube(final double sideLength) {
* @param height height of the cuboid
* @return surface area of given cuboid
*/
- public static double surfaceAreaCuboid(final double length, double width, double height) {
+ public static double surfaceAreaCuboid(final double length, final double width,final double height) {
if (length <= 0) {
- throw new IllegalArgumentException("Length must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_LENGTH);
}
if (width <= 0) {
- throw new IllegalArgumentException("Width must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_WIDTH);
}
if (height <= 0) {
- throw new IllegalArgumentException("Height must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_HEIGHT);
}
return 2 * (length * width + length * height + width * height);
}
@@ -78,10 +84,10 @@ public static double surfaceAreaSphere(final double radius) {
*/
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
if (sideLength <= 0) {
- throw new IllegalArgumentException("");
+ throw new IllegalArgumentException(POSITIVE_SIDE_LENGTH);
}
if (slantHeight <= 0) {
- throw new IllegalArgumentException("slant height must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_SLANT_HEIGHT);
}
double baseArea = sideLength * sideLength;
double lateralSurfaceArea = 2 * sideLength * slantHeight;
@@ -93,14 +99,14 @@ public static double surfaceAreaPyramid(final double sideLength, final double sl
*
* @param length length of a rectangle
* @param width width of a rectangle
- * @return area of given rectangle
+ * @return surface area of given rectangle
*/
public static double surfaceAreaRectangle(final double length, final double width) {
if (length <= 0) {
- throw new IllegalArgumentException("Length must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_LENGTH);
}
if (width <= 0) {
- throw new IllegalArgumentException("Width must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_WIDTH);
}
return length * width;
}
@@ -108,9 +114,9 @@ public static double surfaceAreaRectangle(final double length, final double widt
/**
* Calculate surface area of a cylinder.
*
- * @param radius radius of the floor
+ * @param radius radius of the base circle
* @param height height of the cylinder.
- * @return volume of given cylinder
+ * @return surface area of given cylinder
*/
public static double surfaceAreaCylinder(final double radius, final double height) {
if (radius <= 0) {
@@ -126,11 +132,11 @@ public static double surfaceAreaCylinder(final double radius, final double heigh
* Calculate the area of a square.
*
* @param sideLength side length of square
- * @return area of given square
+ * @return surface area of given square
*/
public static double surfaceAreaSquare(final double sideLength) {
if (sideLength <= 0) {
- throw new IllegalArgumentException("Side Length must be greater than 0");
+ throw new IllegalArgumentException(POSITIVE_SIDE_LENGTH);
}
return sideLength * sideLength;
}
@@ -138,9 +144,9 @@ public static double surfaceAreaSquare(final double sideLength) {
/**
* Calculate the area of a triangle.
*
- * @param base base of triangle
+ * @param baseLength base of triangle
* @param height height of triangle
- * @return area of given triangle
+ * @return surface area of given triangle
*/
public static double surfaceAreaTriangle(final double baseLength, final double height) {
if (baseLength <= 0) {
@@ -155,9 +161,9 @@ public static double surfaceAreaTriangle(final double baseLength, final double h
/**
* Calculate the area of a parallelogram.
*
- * @param base base of a parallelogram
+ * @param baseLength base of a parallelogram
* @param height height of a parallelogram
- * @return area of given parallelogram
+ * @return surface area of given parallelogram
*/
public static double surfaceAreaParallelogram(final double baseLength, final double height) {
if (baseLength <= 0) {
@@ -172,17 +178,17 @@ public static double surfaceAreaParallelogram(final double baseLength, final dou
/**
* Calculate the area of a trapezium.
*
- * @param base1 upper base of trapezium
- * @param base2 bottom base of trapezium
+ * @param baseLength1 upper base of trapezium
+ * @param baseLength2 bottom base of trapezium
* @param height height of trapezium
- * @return area of given trapezium
+ * @return surface area of given trapezium
*/
public static double surfaceAreaTrapezium(final double baseLength1, final double baseLength2, final double height) {
if (baseLength1 <= 0) {
- throw new IllegalArgumentException(POSITIVE_BASE + 1);
+ throw new IllegalArgumentException(POSITIVE_BASE_1 );
}
if (baseLength2 <= 0) {
- throw new IllegalArgumentException(POSITIVE_BASE + 2);
+ throw new IllegalArgumentException(POSITIVE_BASE_2 );
}
if (height <= 0) {
throw new IllegalArgumentException(POSITIVE_HEIGHT);
@@ -194,10 +200,10 @@ public static double surfaceAreaTrapezium(final double baseLength1, final double
* Calculate the area of a circle.
*
* @param radius radius of circle
- * @return area of given circle
+ * @return surface area of given circle
*/
public static double surfaceAreaCircle(final double radius) {
- if (radius <= 0) {
+ if (radius <= 0.0) {
throw new IllegalArgumentException(POSITIVE_RADIUS);
}
return Math.PI * radius * radius;
@@ -210,7 +216,7 @@ public static double surfaceAreaCircle(final double radius) {
* @return surface area of given hemisphere
*/
public static double surfaceAreaHemisphere(final double radius) {
- if (radius <= 0) {
+ if (radius <= 0.0) {
throw new IllegalArgumentException(POSITIVE_RADIUS);
}
return 3 * Math.PI * radius * radius;
@@ -224,10 +230,10 @@ public static double surfaceAreaHemisphere(final double radius) {
* @return surface area of given cone.
*/
public static double surfaceAreaCone(final double radius, final double height) {
- if (radius <= 0) {
+ if (radius <= 0.0) {
throw new IllegalArgumentException(POSITIVE_RADIUS);
}
- if (height <= 0) {
+ if (height <= 0.0) {
throw new IllegalArgumentException(POSITIVE_HEIGHT);
}
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
diff --git a/src/main/java/com/thealgorithms/maths/FastExponentiation.java b/src/main/java/com/thealgorithms/maths/FastExponentiation.java
index 27f49e27ff30..4cbf081b0846 100644
--- a/src/main/java/com/thealgorithms/maths/FastExponentiation.java
+++ b/src/main/java/com/thealgorithms/maths/FastExponentiation.java
@@ -14,8 +14,8 @@
*
Time complexity: O(log(exp)) — much faster than naive exponentiation (O(exp)).
- * - * For more information, please visit {@link https://en.wikipedia.org/wiki/Exponentiation_by_squaring} + /** + * For more information, please visit Exponentiation by Squaring */ public final class FastExponentiation { diff --git a/src/main/java/com/thealgorithms/maths/JosephusProblem.java b/src/main/java/com/thealgorithms/maths/JosephusProblem.java index 98d839011a7f..c34207503e2a 100644 --- a/src/main/java/com/thealgorithms/maths/JosephusProblem.java +++ b/src/main/java/com/thealgorithms/maths/JosephusProblem.java @@ -24,7 +24,8 @@ private JosephusProblem() { /** * Find the Winner of the Circular Game. * - * @param number of friends, n, and an integer k + * @param n number of friends + * @param k an integer * @return return the winner of the game */ diff --git a/src/main/java/com/thealgorithms/maths/Means.java b/src/main/java/com/thealgorithms/maths/Means.java index d77eb1d3f661..cf6b88dd2d9f 100644 --- a/src/main/java/com/thealgorithms/maths/Means.java +++ b/src/main/java/com/thealgorithms/maths/Means.java @@ -1,7 +1,7 @@ package com.thealgorithms.maths; -import java.util.stream.StreamSupport; -import org.apache.commons.collections4.IterableUtils; +//import java.util.stream.StreamSupport; +//import org.apache.commons.collections4.IterableUtils; /** * Utility class for computing various types of statistical means. @@ -47,10 +47,15 @@ private Means() { * Mean */ public static Double arithmetic(final IterableUgly numbers are all positive integers expressible as a product of non-negative + * powers of the given base factors. For example: + *
Design notes (SOLID): + *
Responsibilities: caching, growth, and cursor synchronisation only.
+ * It does not know how to pick the next value; that belongs to the selector.
+ */
+ static final class UglyNumberCache {
- private long computeMinimalCandidate() {
- long res = Long.MAX_VALUE;
- for (final var entry : positions) {
- res = Math.min(res, computeCandidate(entry));
+ private final List
* The algorithm for finding out whether or not a system is in a safe state can
* be described as follows: 1. Let Work and Finish be vectors of length ‘m’ and
* ‘n’ respectively. Initialize: Work= Available Finish [i]=false; for
* i=1,2,……,n 2. Find an i such that both a) Finish [i]=false b) Need_i<=work
- *
+ *
* if no such i exists goto step (4) 3. Work=Work + Allocation_i Finish[i]= true
* goto step(2) 4. If Finish[i]=true for all i, then the system is in safe
* state.
- *
+ *
* Time Complexity: O(n*n*m) Space Complexity: O(n*m) where n = number of
* processes and m = number of resources.
*
- * @author AMRITESH ANAND (https://github.com/amritesh19)
+ * @author AMRIANAND (https://github.com/amritesh19)
*/
public final class BankersAlgorithm {
private BankersAlgorithm() {
From 74fa1bab84cc72f55e52517f55f1fd132eb151a4 Mon Sep 17 00:00:00 2001
From: Nabila1644-iit The input graph is represented as an adjacency list where {@code adjacency.get(u)} returns the
- * set of vertices adjacent to {@code u}. The algorithm runs in time proportional to the number of
- * maximal cliques produced and is widely used for clique enumeration problems. Mutation methods return new instances, keeping each frame independent. The solver is constructed with a {@link PivotStrategy}, making the pivot
+ * heuristic interchangeable without modifying this class (OCP). This façade wires together {@link GraphValidator}, {@link AdjacencyListGraph},
+ * {@link MaxDegreePivotStrategy}, and {@link BronKerboschSolver}, keeping all
+ * callers insulated from the internal decomposition. All methods are stateless and side-effect-free.
+ * No algorithm control-flow lives here — only geometry. For collinear points the method returns {@code true} when {@code k} falls
+ * between {@code i} and {@code j} (inclusive), so that segment endpoints are
+ * treated as hull candidates. Using squared distance avoids floating-point arithmetic while still
+ * providing a consistent total order on distances. Intermediate collinear points are removed so that only the farthest
+ * point along each ray from the pivot is retained. Any class implementing this interface accepts a list of {@link Point}s
+ * and returns the hull vertices in counter-clockwise order. For every pair of points {@code (i, j)}, the algorithm checks whether all
+ * remaining points lie on the same side of the directed line {@code i→j}.
+ * If they do, both endpoints are hull vertices. The algorithm splits the point set into an upper and a lower hull relative
+ * to the line connecting the leftmost and rightmost points, then recursively
+ * finds the extreme point of each sub-hull. Returns points in counter-clockwise order starting from the bottom-most,
+ * left-most point. Provides two named factory methods that preserve the original API while
+ * delegating to independent, interchangeable {@link ConvexHullAlgorithm}
+ * implementations. Algorithms provided:
+ * A splay tree is a self-adjusting binary search tree with the additional property
* that recently accessed elements are quick to access again. It performs basic
- * operations such as insertion, deletion, and searching in O(log n) amortized
- * time,
- * where n is the number of elements in the tree.
- *
- * The key feature of splay trees is the splay operation, which moves a node
- * closer
- * to the root of the tree when it is accessed. This operation helps to maintain
- * good balance and improves the overall performance of the tree. After
- * performing
- * a splay operation, the accessed node becomes the new root of the tree.
- *
- * Splay trees have applications in various areas, including caching, network
- * routing,
- * and dynamic optimality analysis.
+ * operations such as insertion, deletion, and searching in O(log n) amortized time.
*/
public class SplayTree {
- public static final TreeTraversal PRE_ORDER = new PreOrderTraversal();
- public static final TreeTraversal IN_ORDER = new InOrderTraversal();
- public static final TreeTraversal POST_ORDER = new PostOrderTraversal();
+
+ // Preserved public API constants
+ public static final TreeTraversal PRE_ORDER = TraversalStrategy.PRE_ORDER;
+ public static final TreeTraversal IN_ORDER = TraversalStrategy.IN_ORDER;
+ public static final TreeTraversal POST_ORDER = TraversalStrategy.POST_ORDER;
private Node root;
@@ -57,15 +46,18 @@ public void insert(final int key) {
* @return True if the key is found, otherwise false.
*/
public boolean search(int key) {
+ if (isEmpty()) {
+ return false;
+ }
root = splay(root, key);
- return root != null && root.key == key;
+ return root.key == key;
}
/**
* Deletes a key from the SplayTree.
*
* @param key The key to delete.
- * @throws IllegalArgumentException If the tree is empty.
+ * @throws EmptyTreeException If the tree is empty.
*/
public void delete(final int key) {
if (isEmpty()) {
@@ -81,9 +73,9 @@ public void delete(final int key) {
if (root.left == null) {
root = root.right;
} else {
- Node temp = root;
+ Node rightSubtree = root.right;
root = splay(root.left, findMax(root.left).key);
- root.right = temp.right;
+ root.right = rightSubtree;
}
}
@@ -95,171 +87,96 @@ public void delete(final int key) {
*/
public List
- * This method traverses the right children of the subtree until it finds the
- * rightmost node, which contains the maximum key.
- *
- * The zig operation is used to perform a single rotation on a node to move it
- * closer to
- * the root of the tree. It is typically applied when the node is a left child
- * of its parent
- * and needs to be rotated to the right.
- *
- * The zag operation is used to perform a single rotation on a node to move it
- * closer to
- * the root of the tree. It is typically applied when the node is a right child
- * of its parent
- * and needs to be rotated to the left.
- *
- * The splay operation is the core operation of a splay tree. It moves a
- * specified node
- * closer to the root of the tree by performing a series of rotations. The goal
- * of the splay
- * operation is to improve the access time for frequently accessed nodes by
- * bringing them
- * closer to the root.
- *
- * The splay operation consists of three main cases:
- *
- * After performing the splay operation, the accessed node becomes the new root
- * of the tree.
- *
* Based on the difference equation from
* Wikipedia link
*/
diff --git a/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java b/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
index 269880b8ddae..3471983f9c81 100644
--- a/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
+++ b/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
@@ -41,7 +41,7 @@ public class AllPathsFromSourceToTarget {
private final int v;
// To store the paths from source to destination
- static List
* Output:
* {
* {'c', 'a', 't'},
diff --git a/src/main/java/com/thealgorithms/backtracking/KnightsTour.java b/src/main/java/com/thealgorithms/backtracking/KnightsTour.java
index 2c2da659f3aa..d2402151c45e 100644
--- a/src/main/java/com/thealgorithms/backtracking/KnightsTour.java
+++ b/src/main/java/com/thealgorithms/backtracking/KnightsTour.java
@@ -6,12 +6,12 @@
/**
* The KnightsTour class solves the Knight's Tour problem using backtracking.
- *
+ *
* Problem Statement:
* Given an N*N board with a knight placed on the first block, the knight must
* move according to chess rules and visit each square on the board exactly once.
* The class outputs the sequence of moves for the knight.
- *
+ *
* Example:
* Input: N = 8 (8x8 chess board)
* Output: The sequence of numbers representing the order in which the knight visits each square.
diff --git a/src/main/java/com/thealgorithms/backtracking/MColoring.java b/src/main/java/com/thealgorithms/backtracking/MColoring.java
index d0188dfd13aa..647ab4807302 100644
--- a/src/main/java/com/thealgorithms/backtracking/MColoring.java
+++ b/src/main/java/com/thealgorithms/backtracking/MColoring.java
@@ -10,11 +10,11 @@
* Node class represents a graph node. Each node is associated with a color
* (initially 1) and contains a set of edges representing its adjacent nodes.
*
- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * @author Bama Charan Chhandogi (...)
*/
class Node {
int color = 1; // Initial color for each node
- Set
* The goal is to find a path from a starting position to the target position
* (map[6][5]) while navigating through the maze.
*/
diff --git a/src/main/java/com/thealgorithms/backtracking/NQueens.java b/src/main/java/com/thealgorithms/backtracking/NQueens.java
index 404f677738a0..9b80256b3a45 100644
--- a/src/main/java/com/thealgorithms/backtracking/NQueens.java
+++ b/src/main/java/com/thealgorithms/backtracking/NQueens.java
@@ -10,21 +10,21 @@
* which N queens can be placed on the board such no two queens attack each
* other. Ex. N = 6 Solution= There are 4 possible ways Arrangement: 1 ".Q....",
* "...Q..", ".....Q", "Q.....", "..Q...", "....Q."
- *
+ *
* Arrangement: 2 "..Q...", ".....Q", ".Q....", "....Q.", "Q.....", "...Q.."
- *
+ *
* Arrangement: 3 "...Q..", "Q.....", "....Q.", ".Q....", ".....Q", "..Q..."
- *
+ *
* Arrangement: 4 "....Q.", "..Q...", "Q.....", ".....Q", "...Q..", ".Q...."
- *
+ *
* Solution: Brute Force approach:
- *
+ *
* Generate all possible arrangement to place N queens on N*N board. Check each
* board if queens are placed safely. If it is safe, include arrangement in
* solution set. Otherwise, ignore it
- *
+ *
* Optimized solution: This can be solved using backtracking in below steps
- *
+ *
* Start with first column and place queen on first row Try placing queen in a
* row on second column If placing second queen in second column attacks any of
* the previous queens, change the row in second column otherwise move to next
diff --git a/src/main/java/com/thealgorithms/backtracking/PowerSum.java b/src/main/java/com/thealgorithms/backtracking/PowerSum.java
index b34ba660ebd7..67dd000636ee 100644
--- a/src/main/java/com/thealgorithms/backtracking/PowerSum.java
+++ b/src/main/java/com/thealgorithms/backtracking/PowerSum.java
@@ -6,7 +6,7 @@
* of unique, natural numbers.
* For example, if N=100 and X=3, we have to find all combinations of unique cubes adding up to 100.
* The only solution is 1^3 + 2^3 + 3^3 + 4^3. Therefore, the output will be 1.
- *
+ *
* N is represented by the parameter 'targetSum' in the code.
* X is represented by the parameter 'power' in the code.
*/
diff --git a/src/main/java/com/thealgorithms/backtracking/UniquePermutation.java b/src/main/java/com/thealgorithms/backtracking/UniquePermutation.java
index 4804e247ab03..9f282b76d33d 100644
--- a/src/main/java/com/thealgorithms/backtracking/UniquePermutation.java
+++ b/src/main/java/com/thealgorithms/backtracking/UniquePermutation.java
@@ -6,11 +6,11 @@
/**
* Generates all UNIQUE permutations of a string, even when duplicate characters exist.
- *
+ *
* Example:
* Input: "AAB"
* Output: ["AAB", "ABA", "BAA"]
- *
+ *
* Time Complexity: O(n! * n)
*/
public final class UniquePermutation {
diff --git a/src/main/java/com/thealgorithms/backtracking/WordPatternMatcher.java b/src/main/java/com/thealgorithms/backtracking/WordPatternMatcher.java
index 1854cab20a7f..fbf53bffcca2 100644
--- a/src/main/java/com/thealgorithms/backtracking/WordPatternMatcher.java
+++ b/src/main/java/com/thealgorithms/backtracking/WordPatternMatcher.java
@@ -5,16 +5,16 @@
/**
* Class to determine if a pattern matches a string using backtracking.
- *
+ *
* Example:
* Pattern: "abab"
* Input String: "JavaPythonJavaPython"
* Output: true
- *
+ *
* Pattern: "aaaa"
* Input String: "JavaJavaJavaJava"
* Output: true
- *
+ *
* Pattern: "aabb"
* Input String: "JavaPythonPythonJava"
* Output: false
diff --git a/src/main/java/com/thealgorithms/backtracking/WordSearch.java b/src/main/java/com/thealgorithms/backtracking/WordSearch.java
index 452f17b6ace6..ddb8b8baf4d6 100644
--- a/src/main/java/com/thealgorithms/backtracking/WordSearch.java
+++ b/src/main/java/com/thealgorithms/backtracking/WordSearch.java
@@ -2,12 +2,12 @@
/**
* Word Search Problem
- *
+ *
* This class solves the word search problem where given an m x n grid of characters (board)
* and a target word, the task is to check if the word exists in the grid.
* The word can be constructed from sequentially adjacent cells (horizontally or vertically),
* and the same cell may not be used more than once in constructing the word.
- *
+ *
* Example:
* - For board =
* [
@@ -18,19 +18,19 @@
* and word = "ABCCED", -> returns true
* and word = "SEE", -> returns true
* and word = "ABCB", -> returns false
- *
+ *
* Solution:
* - Depth First Search (DFS) with backtracking is used to explore possible paths from any cell
* matching the first letter of the word. DFS ensures that we search all valid paths, while
* backtracking helps in reverting decisions when a path fails to lead to a solution.
- *
+ *
* Time Complexity: O(m * n * 3^L)
* - m = number of rows in the board
* - n = number of columns in the board
* - L = length of the word
* - For each cell, we look at 3 possible directions (since we exclude the previously visited direction),
* and we do this for L letters.
- *
+ *
* Space Complexity: O(L)
* - Stack space for the recursive DFS function, where L is the maximum depth of recursion (length of the word).
*/
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BcdConversion.java b/src/main/java/com/thealgorithms/bitmanipulation/BcdConversion.java
index e6bd35720d9f..75d4e8300757 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/BcdConversion.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/BcdConversion.java
@@ -2,12 +2,12 @@
/**
* This class provides methods to convert between BCD (Binary-Coded Decimal) and decimal numbers.
- *
+ *
* BCD is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of binary digits, usually four or eight.
- *
+ *
* For more information, refer to the
* Binary-Coded Decimal Wikipedia page.
- *
+ *
* Example usage:
*
* Example:
* 26 (11010) -> 10 (01010)
* 1 (1) -> 0 (0)
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/CountBitsFlip.java b/src/main/java/com/thealgorithms/bitmanipulation/CountBitsFlip.java
index 8d2c757e5e0a..97f381ff87f5 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/CountBitsFlip.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/CountBitsFlip.java
@@ -2,16 +2,16 @@
/**
* Implementation to count number of bits to be flipped to convert A to B
- *
+ *
* Problem: Given two numbers A and B, count the number of bits needed to be
* flipped to convert A to B.
- *
+ *
* Example:
* A = 10 (01010 in binary)
* B = 20 (10100 in binary)
* XOR = 30 (11110 in binary) - positions where bits differ
* Answer: 4 bits need to be flipped
- *
+ *
* Time Complexity: O(log n) - where n is the number of set bits
* Space Complexity: O(1)
*
@@ -25,7 +25,7 @@ private CountBitsFlip() {
/**
* Counts the number of bits that need to be flipped to convert a to b
- *
+ *
* Algorithm:
* 1. XOR a and b to get positions where bits differ
* 2. Count the number of set bits in the XOR result
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/FirstDifferentBit.java b/src/main/java/com/thealgorithms/bitmanipulation/FirstDifferentBit.java
index 9a761c572e2c..b9f8c0d6d43e 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/FirstDifferentBit.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/FirstDifferentBit.java
@@ -3,7 +3,7 @@
/**
* This class provides a method to find the first differing bit
* between two integers.
- *
+ *
* Example:
* x = 10 (1010 in binary)
* y = 12 (1100 in binary)
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java b/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java
index 2398b8214371..a0e26f4cb2ff 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java
@@ -4,12 +4,12 @@
/**
* Find Highest Set Bit
- *
+ *
* This class provides a utility method to calculate the position of the highest
* (most significant) bit that is set to 1 in a given non-negative integer.
* It is often used in bit manipulation tasks to find the left-most set bit in binary
* representation of a number.
- *
+ *
* Example:
* - For input 18 (binary 10010), the highest set bit is at position 4 (zero-based index).
*
@@ -25,7 +25,7 @@ private HighestSetBit() {
/**
* Finds the highest (most significant) set bit in the given integer.
* The method returns the position (index) of the highest set bit as an {@link Optional}.
- *
+ *
* - If the number is 0, no bits are set, and the method returns {@link Optional#empty()}.
* - If the number is negative, the method throws {@link IllegalArgumentException}.
*
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java b/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java
index 1b8962344ea7..cfb3837ed42d 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java
@@ -6,8 +6,8 @@
* Specifically, it includes a method to find the index of the rightmost set bit
* in an integer.
* This class is not meant to be instantiated.
- *
- * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ *
+ * Author: Bama Charan Chhando(https://github.com/BamaCharanChhandogi)
*/
public final class IndexOfRightMostSetBit {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java b/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java
index 09d5383322ff..234458aa41c0 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java
@@ -2,7 +2,7 @@
/**
* Checks whether a number is even
- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * @author Bama Charan Chhandogi (...)
*/
public final class IsEven {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java b/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java
index 4cdf3c6faa3e..6807f34a6e07 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/IsPowerTwo.java
@@ -5,7 +5,7 @@
* A power of two is a number that can be expressed as 2^n where n is a non-negative integer.
* This class provides a method to determine if a given integer is a power of two using bit manipulation.
*
- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * @author Bama Charan Chhandogi (...)
*/
public final class IsPowerTwo {
private IsPowerTwo() {
@@ -13,7 +13,7 @@ private IsPowerTwo() {
/**
* Checks if the given integer is a power of two.
- *
+ *
* A number is considered a power of two if it is greater than zero and
* has exactly one '1' bit in its binary representation. This method
* uses the property that for any power of two (n), the expression
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java
index 127b6fa2c0b1..3b4d148a5cb9 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/LowestSetBit.java
@@ -2,7 +2,7 @@
/**
* Lowest Set Bit
- * @author Prayas Kumar (https://github.com/prayas7102)
+ * @author Prayas Kumar (...)
*/
public final class LowestSetBit {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java b/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java
index 17e1a73ec062..e167f94a06a6 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/NonRepeatingNumberFinder.java
@@ -3,17 +3,17 @@
/**
* A utility class to find the non-repeating number in an array where every other number repeats.
* This class contains a method to identify the single unique number using bit manipulation.
- *
+ *
* The solution leverages the properties of the XOR operation, which states that:
* - x ^ x = 0 for any integer x (a number XORed with itself is zero)
* - x ^ 0 = x for any integer x (a number XORed with zero is the number itself)
- *
+ *
* Using these properties, we can find the non-repeating number in linear time with constant space.
- *
+ *
* Example:
* Given the input array [2, 3, 5, 2, 3], the output will be 5 since it does not repeat.
*
- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * @author Bama Charan...ranChhandogi)
*/
public final class NonRepeatingNumberFinder {
private NonRepeatingNumberFinder() {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/NumberAppearingOddTimes.java b/src/main/java/com/thealgorithms/bitmanipulation/NumberAppearingOddTimes.java
index bd4868d4dbd5..88d5f051bd72 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/NumberAppearingOddTimes.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/NumberAppearingOddTimes.java
@@ -4,20 +4,20 @@
* This class provides a method to find the element that appears an
* odd number of times in an array. All other elements in the array
* must appear an even number of times for the logic to work.
- *
+ *
* The solution uses the XOR operation, which has the following properties:
* - a ^ a = 0 (XOR-ing the same numbers cancels them out)
* - a ^ 0 = a
* - XOR is commutative and associative.
- *
+ *
* Time Complexity: O(n), where n is the size of the array.
* Space Complexity: O(1), as no extra space is used.
- *
+ *
* Usage Example:
* int result = NumberAppearingOddTimes.findOddOccurrence(new int[]{1, 2, 1, 2, 3});
* // result will be 3
*
- * @author Lakshyajeet Singh Goyal (https://github.com/DarkMatter-999)
+ * @author Lakshyajeet SGoyal (https://github.com/DarkMatter-999)
*/
public final class NumberAppearingOddTimes {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java b/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java
index a2da37aa81ee..128775dba000 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java
@@ -3,11 +3,11 @@
/**
* This class provides a method to determine whether two integers have
* different signs. It utilizes the XOR operation on the two numbers:
- *
+ *
* - If two numbers have different signs, their most significant bits
* (sign bits) will differ, resulting in a negative XOR result.
* - If two numbers have the same sign, the XOR result will be non-negative.
- *
+ *
* Time Complexity: O(1) - Constant time operation.
* Space Complexity: O(1) - No extra space used.
*
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/OneBitDifference.java b/src/main/java/com/thealgorithms/bitmanipulation/OneBitDifference.java
index afec0188e299..3324cb1fef73 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/OneBitDifference.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/OneBitDifference.java
@@ -3,7 +3,7 @@
/**
* This class provides a method to detect if two integers
* differ by exactly one bit flip.
- *
+ *
* Example:
* 1 (0001) and 2 (0010) differ by exactly one bit flip.
* 7 (0111) and 3 (0011) differ by exactly one bit flip.
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/OnesComplement.java b/src/main/java/com/thealgorithms/bitmanipulation/OnesComplement.java
index aae3a996e49d..97908141618b 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/OnesComplement.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/OnesComplement.java
@@ -1,8 +1,8 @@
package com.thealgorithms.bitmanipulation;
/**
- * @author - https://github.com/Monk-AbhinayVerma
- * @Wikipedia - https://en.wikipedia.org/wiki/Ones%27_complement
+ * @author - ...
+ * @Wikipedia - ...
* The class OnesComplement computes the complement of binary number
* and returns
* the complemented binary string.
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java b/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java
index 12c269d9be48..56c97e7322d3 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java
@@ -4,14 +4,14 @@
* This class provides a method to reverse the bits of a 32-bit integer.
* Reversing the bits means that the least significant bit (LSB) becomes
* the most significant bit (MSB) and vice versa.
- *
+ *
* Example:
* Input (binary): 00000010100101000001111010011100 (43261596)
* Output (binary): 00111001011110000010100101000000 (964176192)
- *
+ *
* Time Complexity: O(32) - A fixed number of 32 iterations
* Space Complexity: O(1) - No extra space used
- *
+ *
* Note:
* - If the input is negative, Java handles it using two’s complement representation.
* - This function works on 32-bit integers by default.
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperations.java b/src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperations.java
index 624a4e2b858a..98f5d867777a 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperations.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/SingleBitOperations.java
@@ -4,19 +4,19 @@
* A utility class for performing single-bit operations on integers.
* These operations include flipping, setting, clearing, and getting
* individual bits at specified positions.
- *
+ *
* Bit positions are zero-indexed (i.e., the least significant bit is at position 0).
* These methods leverage bitwise operations for optimal performance.
- *
+ *
* Examples:
* - `flipBit(3, 1)` flips the bit at index 1 in binary `11` (result: `1`).
* - `setBit(4, 0)` sets the bit at index 0 in `100` (result: `101` or 5).
* - `clearBit(7, 1)` clears the bit at index 1 in `111` (result: `101` or 5).
* - `getBit(6, 0)` checks if the least significant bit is set (result: `0`).
- *
+ *
* Time Complexity: O(1) for all operations.
- *
- * Author: lukasb1b (https://github.com/lukasb1b)
+ *
+ * Aulukasb1b (https://github.com/lukasb1b)
*/
public final class SingleBitOperations {
private SingleBitOperations() {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/SwapAdjacentBits.java b/src/main/java/com/thealgorithms/bitmanipulation/SwapAdjacentBits.java
index 98a7de8bdf1a..694acea67d36 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/SwapAdjacentBits.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/SwapAdjacentBits.java
@@ -3,11 +3,11 @@
/**
* A utility class to swap every pair of adjacent bits in a given integer.
* This operation shifts the even-positioned bits to odd positions and vice versa.
- *
+ *
* Example:
* - Input: 2 (binary: `10`) → Output: 1 (binary: `01`)
* - Input: 43 (binary: `101011`) → Output: 23 (binary: `010111`)
- *
+ *
* **Explanation of the Algorithm:**
* 1. Mask even-positioned bits: Using `0xAAAAAAAA` (binary: `101010...`),
* which selects bits in even positions.
@@ -17,13 +17,13 @@
* - Right-shift even-positioned bits by 1 to move them to odd positions.
* - Left-shift odd-positioned bits by 1 to move them to even positions.
* 4. Combine both shifted results using bitwise OR (`|`) to produce the final result.
- *
+ *
* Use Case: This algorithm can be useful in applications involving low-level bit manipulation,
* such as encoding, data compression, or cryptographic transformations.
- *
+ *
* Time Complexity: O(1) (constant time, since operations are bitwise).
- *
- * Author: Lakshyajeet Singh Goyal (https://github.com/DarkMatter-999)
+ *
+ * Author: LakshSingh Goyal (https://github.com/DarkMatter-999)
*/
public final class SwapAdjacentBits {
private SwapAdjacentBits() {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/TwosComplement.java b/src/main/java/com/thealgorithms/bitmanipulation/TwosComplement.java
index 9b8cecd791a6..146a3cf5cb4c 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/TwosComplement.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/TwosComplement.java
@@ -13,7 +13,7 @@
*
* Algorithm originally suggested by Jon von Neumann.
*
- * @author Abhinay Verma (https://github.com/Monk-AbhinayVerma)
+ * @author Abhinay Verma (...)
*/
public final class TwosComplement {
private TwosComplement() {
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/Xs3Conversion.java b/src/main/java/com/thealgorithms/bitmanipulation/Xs3Conversion.java
index b22abc0c04ff..1b8a1b7252eb 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/Xs3Conversion.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/Xs3Conversion.java
@@ -2,12 +2,12 @@
/**
* This class provides methods to convert between XS-3 (Excess-3) and binary.
- *
+ *
* Excess-3, also called XS-3, is a binary-coded decimal (BCD) code in which each decimal digit is represented by its corresponding 4-bit binary value plus 3.
- *
+ *
* For more information, refer to the
* Excess-3 Wikipedia page.
- *
+ *
* Example usage:
*
* E(x) = (a * x + b) mod m
* D(y) = a^-1 * (y - b) mod m
- *
+ *
* where:
* - E(x) is the encrypted character,
* - D(y) is the decrypted character,
@@ -15,7 +15,7 @@
* - x is the index of the plaintext character,
* - y is the index of the ciphertext character,
* - m is the size of the alphabet (26 for the English alphabet).
- *
+ *
* The class provides methods for encrypting and decrypting messages, as well as a main method to demonstrate its usage.
*/
final class AffineCipher {
@@ -23,8 +23,8 @@ private AffineCipher() {
}
// Key values of a and b
- static int a = 17;
- static int b = 20;
+ static final int a = 17;
+ static final int b = 20;
/**
* Encrypts a message using the Affine cipher.
diff --git a/src/main/java/com/thealgorithms/ciphers/AtbashCipher.java b/src/main/java/com/thealgorithms/ciphers/AtbashCipher.java
index 9169aa82bd75..8b9b48dad06d 100644
--- a/src/main/java/com/thealgorithms/ciphers/AtbashCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/AtbashCipher.java
@@ -3,14 +3,14 @@
/**
* The Atbash cipher is a classic substitution cipher that substitutes each letter
* with its opposite letter in the alphabet.
- *
+ *
* For example:
* - 'A' becomes 'Z', 'B' becomes 'Y', 'C' becomes 'X', and so on.
* - Similarly, 'a' becomes 'z', 'b' becomes 'y', and so on.
- *
+ *
* The cipher works identically for both uppercase and lowercase letters.
* Non-alphabetical characters remain unchanged in the output.
- *
+ *
* This cipher is symmetric, meaning that applying the cipher twice will return
* the original text. Therefore, the same function is used for both encryption and decryption.
*
diff --git a/src/main/java/com/thealgorithms/ciphers/Autokey.java b/src/main/java/com/thealgorithms/ciphers/Autokey.java
index bb67f512accf..3a07a9328c78 100644
--- a/src/main/java/com/thealgorithms/ciphers/Autokey.java
+++ b/src/main/java/com/thealgorithms/ciphers/Autokey.java
@@ -5,7 +5,7 @@
* as it improves upon the classic Vigenère Cipher by using the plaintext itself to
* extend the key. This makes it harder to break using frequency analysis, as it
* doesn’t rely solely on a repeated key.
- * https://en.wikipedia.org/wiki/Autokey_cipher
+ * ...
*
* @author bennybebo
*/
diff --git a/src/main/java/com/thealgorithms/ciphers/BaconianCipher.java b/src/main/java/com/thealgorithms/ciphers/BaconianCipher.java
index 16dfd6e674af..945cc372499a 100644
--- a/src/main/java/com/thealgorithms/ciphers/BaconianCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/BaconianCipher.java
@@ -7,7 +7,7 @@
* The Baconian Cipher is a substitution cipher where each letter is represented
* by a group of five binary digits (A's and B's). It can also be used to hide
* messages within other texts, making it a simple form of steganography.
- * https://en.wikipedia.org/wiki/Bacon%27s_cipher
+ * ...
*
* @author Bennybebo
*/
diff --git a/src/main/java/com/thealgorithms/ciphers/Blowfish.java b/src/main/java/com/thealgorithms/ciphers/Blowfish.java
index 58b1d042c9ca..33439c6c199a 100644
--- a/src/main/java/com/thealgorithms/ciphers/Blowfish.java
+++ b/src/main/java/com/thealgorithms/ciphers/Blowfish.java
@@ -11,7 +11,7 @@
public class Blowfish {
// Initializing substitution boxes
- String[][] sBox = {
+ final String[][] sBox = {
{
"d1310ba6",
"98dfb5ac",
@@ -1047,7 +1047,7 @@ public class Blowfish {
};
// Initializing subkeys with digits of pi
- String[] subKeys = {
+ final String[] subKeys = {
"243f6a88",
"85a308d3",
"13198a2e",
@@ -1069,7 +1069,7 @@ public class Blowfish {
};
// Initializing modVal to 2^32
- long modVal = 4294967296L;
+ final long modVal = 4294967296L;
/**
* This method returns binary representation of the hexadecimal number passed as parameter
@@ -1139,7 +1139,7 @@ private String xor(String a, String b) {
* passed as parameters
*/
private String addBin(String a, String b) {
- String ans = "";
+ String ans;
long n1 = Long.parseUnsignedLong(a, 16);
long n2 = Long.parseUnsignedLong(b, 16);
n1 = (n1 + n2) % modVal;
@@ -1155,7 +1155,7 @@ private String addBin(String a, String b) {
*/
private String f(String plainText) {
String[] a = new String[4];
- String ans = "";
+ String ans;
for (int i = 0; i < 8; i += 2) {
// column number for S-box is a 8-bit value
long col = Long.parseUnsignedLong(hexToBin(plainText.substring(i, i + 2)), 2);
diff --git a/src/main/java/com/thealgorithms/ciphers/DES.java b/src/main/java/com/thealgorithms/ciphers/DES.java
index 7f3eed70f3c2..a8d534b15cd2 100644
--- a/src/main/java/com/thealgorithms/ciphers/DES.java
+++ b/src/main/java/com/thealgorithms/ciphers/DES.java
@@ -2,7 +2,7 @@
/**
* This class is build to demonstrate the application of the DES-algorithm
- * (https://en.wikipedia.org/wiki/Data_Encryption_Standard) on a plain English message. The supplied
+ * (...) on a plain English message. The supplied
* key must be in form of a 64 bit binary String.
*/
public class DES {
diff --git a/src/main/java/com/thealgorithms/ciphers/ECC.java b/src/main/java/com/thealgorithms/ciphers/ECC.java
index 7b1e37f0e1e1..e6225c345bd6 100644
--- a/src/main/java/com/thealgorithms/ciphers/ECC.java
+++ b/src/main/java/com/thealgorithms/ciphers/ECC.java
@@ -9,7 +9,7 @@
* elliptic curves over finite fields. ECC provides a higher level of security with smaller key sizes compared
* to other public-key methods like RSA, making it particularly suitable for environments where computational
* resources are limited, such as mobile devices and embedded systems.
- *
+ *
* This class implements elliptic curve cryptography, providing encryption and decryption
* functionalities based on public and private key pairs.
*
diff --git a/src/main/java/com/thealgorithms/ciphers/PermutationCipher.java b/src/main/java/com/thealgorithms/ciphers/PermutationCipher.java
index ce443545db1d..686dfb3e4219 100644
--- a/src/main/java/com/thealgorithms/ciphers/PermutationCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/PermutationCipher.java
@@ -7,7 +7,7 @@
* A Java implementation of Permutation Cipher.
* It is a type of transposition cipher in which the plaintext is divided into blocks
* and the characters within each block are rearranged according to a fixed permutation key.
- *
+ *
* For example, with key {3, 1, 2} and plaintext "HELLO", the text is divided into blocks
* of 3 characters: "HEL" and "LO" (with padding). The characters are then rearranged
* according to the key positions.
diff --git a/src/main/java/com/thealgorithms/ciphers/RSA.java b/src/main/java/com/thealgorithms/ciphers/RSA.java
index 28af1a62032a..8c6242ecb68e 100644
--- a/src/main/java/com/thealgorithms/ciphers/RSA.java
+++ b/src/main/java/com/thealgorithms/ciphers/RSA.java
@@ -7,11 +7,11 @@
* RSA is an asymmetric cryptographic algorithm used for secure data encryption and decryption.
* It relies on a pair of keys: a public key (used for encryption) and a private key
* (used for decryption). The algorithm is based on the difficulty of factoring large prime numbers.
- *
+ *
* This implementation includes key generation, encryption, and decryption methods that can handle both
* text-based messages and BigInteger inputs. For more details on RSA:
* RSA Cryptosystem - Wikipedia.
- *
+ *
* Example Usage:
*
* The Vigenère Cipher is a polyalphabetic substitution cipher that uses a
* keyword to shift letters in the plaintext by different amounts, depending
* on the corresponding character in the keyword. It wraps around the alphabet,
* ensuring the shifts are within 'A'-'Z' or 'a'-'z'.
- *
+ *
* Non-alphabetic characters (like spaces, punctuation) are kept unchanged.
- *
+ *
* Encryption Example:
* - Plaintext: "Hello World!"
* - Key: "suchsecret"
* - Encrypted Text: "Zynsg Yfvev!"
- *
+ *
* Decryption Example:
* - Ciphertext: "Zynsg Yfvev!"
* - Key: "suchsecret"
* - Decrypted Text: "Hello World!"
- *
+ *
* Wikipedia Reference:
* Vigenère Cipher - Wikipedia
*
diff --git a/src/main/java/com/thealgorithms/ciphers/XORCipher.java b/src/main/java/com/thealgorithms/ciphers/XORCipher.java
index a612ccfbcdef..9070255b9c1d 100644
--- a/src/main/java/com/thealgorithms/ciphers/XORCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/XORCipher.java
@@ -9,22 +9,22 @@
* using a given key. This cipher works by applying the XOR bitwise operation between
* the bytes of the input text and the corresponding bytes of the key (repeating the key
* if necessary).
- *
+ *
* Usage:
* - Encryption: Converts plaintext into a hexadecimal-encoded ciphertext.
* - Decryption: Converts the hexadecimal ciphertext back into plaintext.
- *
+ *
* Characteristics:
* - Symmetric: The same key is used for both encryption and decryption.
* - Simple but vulnerable: XOR encryption is insecure for real-world cryptography,
* especially when the same key is reused.
- *
+ *
* Example:
* Plaintext: "Hello!"
* Key: "key"
* Encrypted: "27090c03120b"
* Decrypted: "Hello!"
- *
+ *
* Reference: XOR Cipher - Wikipedia
*
* @author lcsjunior
diff --git a/src/main/java/com/thealgorithms/ciphers/a5/A5Cipher.java b/src/main/java/com/thealgorithms/ciphers/a5/A5Cipher.java
index cc2e9105229a..0e39c7a9ea81 100644
--- a/src/main/java/com/thealgorithms/ciphers/a5/A5Cipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/a5/A5Cipher.java
@@ -5,7 +5,7 @@
/**
* The A5Cipher class implements the A5/1 stream cipher, which is a widely used
* encryption algorithm, particularly in mobile communications.
- *
+ *
* This implementation uses a key stream generator to produce a stream of bits
* that are XORed with the plaintext bits to produce the ciphertext.
*
@@ -32,7 +32,7 @@ public A5Cipher(BitSet sessionKey, BitSet frameCounter) {
/**
* Encrypts the given plaintext bits using the A5/1 cipher algorithm.
- *
+ *
* This method generates a key stream and XORs it with the provided plaintext
* bits to produce the ciphertext.
*
@@ -52,7 +52,7 @@ public BitSet encrypt(BitSet plainTextBits) {
/**
* Resets the internal counter of the key stream generator.
- *
+ *
* This method can be called to re-initialize the state of the key stream
* generator, allowing for new key streams to be generated for subsequent
* encryptions.
diff --git a/src/main/java/com/thealgorithms/compression/LZ78.java b/src/main/java/com/thealgorithms/compression/LZ78.java
index 904c379cc2a2..28fdd50d521f 100644
--- a/src/main/java/com/thealgorithms/compression/LZ78.java
+++ b/src/main/java/com/thealgorithms/compression/LZ78.java
@@ -55,7 +55,7 @@ public record Token(int index, char nextChar) {
* Each node represents a phrase and can have child nodes for extended phrases.
*/
private static final class TrieNode {
- Map
* This class supports inversion and composition of affine transformations.
* It is immutable, meaning each instance represents a fixed transformation.
*/
diff --git a/src/main/java/com/thealgorithms/conversions/AnytoAny.java b/src/main/java/com/thealgorithms/conversions/AnytoAny.java
index e7bdbc2b79c4..06ba653af076 100644
--- a/src/main/java/com/thealgorithms/conversions/AnytoAny.java
+++ b/src/main/java/com/thealgorithms/conversions/AnytoAny.java
@@ -2,7 +2,7 @@
/**
* A utility class for converting numbers from any base to any other base.
- *
+ *
* This class provides a method to convert a source number from a given base
* to a destination number in another base. Valid bases range from 2 to 10.
*/
diff --git a/src/main/java/com/thealgorithms/conversions/Base64.java b/src/main/java/com/thealgorithms/conversions/Base64.java
index 5219c4ba7f4e..aebca161839f 100644
--- a/src/main/java/com/thealgorithms/conversions/Base64.java
+++ b/src/main/java/com/thealgorithms/conversions/Base64.java
@@ -8,14 +8,14 @@
* Base64 is a group of binary-to-text encoding schemes that represent binary data
* in an ASCII string format by translating it into a radix-64 representation.
* Each base64 digit represents exactly 6 bits of data.
- *
+ *
* Base64 encoding is commonly used when there is a need to encode binary data
* that needs to be stored and transferred over media that are designed to deal
* with textual data.
- *
- * Wikipedia Reference: https://en.wikipedia.org/wiki/Base64
+ *
+ * Wikipedia Refhttps://en.wikipedia.org/wiki/Base64
* Author: Nithin U.
- * Github: https://github.com/NithinU2802
+ * https://github.com/NithinU2802
*/
public final class Base64 {
diff --git a/src/main/java/com/thealgorithms/conversions/IPConverter.java b/src/main/java/com/thealgorithms/conversions/IPConverter.java
index 765cb0201dd5..21821553933d 100644
--- a/src/main/java/com/thealgorithms/conversions/IPConverter.java
+++ b/src/main/java/com/thealgorithms/conversions/IPConverter.java
@@ -4,7 +4,7 @@
* Converts an IPv4 address to its binary equivalent and vice-versa.
* IP to Binary: Converts an IPv4 address to its binary equivalent.
* Example: 127.3.4.5 -> 01111111.00000011.00000100.00000101
- *
+ *
* Binary to IP: Converts a binary equivalent to an IPv4 address.
* Example: 01111111.00000011.00000100.00000101 -> 127.3.4.5
*
diff --git a/src/main/java/com/thealgorithms/conversions/IPv6Converter.java b/src/main/java/com/thealgorithms/conversions/IPv6Converter.java
index d42ffd027514..bf13e5597cff 100644
--- a/src/main/java/com/thealgorithms/conversions/IPv6Converter.java
+++ b/src/main/java/com/thealgorithms/conversions/IPv6Converter.java
@@ -6,7 +6,7 @@
/**
* A utility class for converting between IPv6 and IPv4 addresses.
- *
+ *
* - Converts IPv4 to IPv6-mapped IPv6 address.
* - Extracts IPv4 address from IPv6-mapped IPv6.
* - Handles exceptions for invalid inputs.
diff --git a/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java b/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java
index e85c608af5d0..85168d0d9587 100644
--- a/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java
+++ b/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java
@@ -60,7 +60,7 @@ private static String convertToWords(int number) {
int hundredsDigit = number / 100;
if (hundredsDigit > 0) {
- if (result.length() > 0) {
+ if (!result.isEmpty()) {
result.insert(0, " ");
}
result.insert(0, String.format("%s Hundred", BASE_NUMBERS_MAP.get(hundredsDigit)));
@@ -93,7 +93,7 @@ public static String integerToEnglishWords(int number) {
if (index > 0) {
subResult += " " + THOUSAND_POWER_MAP.get(index);
}
- if (result.length() > 0) {
+ if (!result.isEmpty()) {
result.insert(0, " ");
}
result.insert(0, subResult);
diff --git a/src/main/java/com/thealgorithms/conversions/MorseCodeConverter.java b/src/main/java/com/thealgorithms/conversions/MorseCodeConverter.java
index a3973da0c586..383ffe334bef 100644
--- a/src/main/java/com/thealgorithms/conversions/MorseCodeConverter.java
+++ b/src/main/java/com/thealgorithms/conversions/MorseCodeConverter.java
@@ -7,10 +7,10 @@
* Converts text to Morse code and vice-versa.
* Text to Morse code: Each letter is separated by a space and each word is separated by a pipe (|).
* Example: "HELLO WORLD" -> ".... . .-.. .-.. --- | .-- --- .-. .-.. -.."
- *
+ *
* Morse code to text: Each letter is separated by a space and each word is separated by a pipe (|).
* Example: ".... . .-.. .-.. --- | .-- --- .-. .-.. -.." -> "HELLO WORLD"
- *
+ *
* Applications: Used in radio communications and algorithmic challenges.
*
* @author Hardvan
diff --git a/src/main/java/com/thealgorithms/conversions/TemperatureConverter.java b/src/main/java/com/thealgorithms/conversions/TemperatureConverter.java
index 901db17c665d..b9dd2315bc96 100644
--- a/src/main/java/com/thealgorithms/conversions/TemperatureConverter.java
+++ b/src/main/java/com/thealgorithms/conversions/TemperatureConverter.java
@@ -12,7 +12,7 @@
*
* This class is final and cannot be instantiated.
*
- * @author krishna-medapati (https://github.com/krishna-medapati)
+ * @author krishna-medapati (...)
* @see Wikipedia: Temperature Conversion
*/
public final class TemperatureConverter {
diff --git a/src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java b/src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java
index fa048434a187..457088ce424c 100644
--- a/src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java
+++ b/src/main/java/com/thealgorithms/datastructures/caches/FIFOCache.java
@@ -51,8 +51,8 @@ public final class FIFOCache
* For more information, refer to:
* MRU on Wikipedia.
*
diff --git a/src/main/java/com/thealgorithms/datastructures/caches/RRCache.java b/src/main/java/com/thealgorithms/datastructures/caches/RRCache.java
index 1821872be9cd..bb88f3c954ba 100644
--- a/src/main/java/com/thealgorithms/datastructures/caches/RRCache.java
+++ b/src/main/java/com/thealgorithms/datastructures/caches/RRCache.java
@@ -53,8 +53,8 @@ public final class RRCache
* The implementation leverages DFS to attempt to color the graph using two colors. If we can color the graph such
* that no two adjacent vertices have the same color, the graph is bipartite.
- *
+ *
* Example:
* Input (Adjacency Matrix):
* {{0, 1, 0, 1},
* {1, 0, 1, 0},
* {0, 1, 0, 1},
* {1, 0, 1, 0}}
- *
+ *
* Output: YES (This graph is bipartite)
- *
+ *
* Input (Adjacency Matrix):
* {{0, 1, 1, 0},
* {1, 0, 1, 0},
* {1, 1, 0, 1},
* {0, 0, 1, 0}}
- *
+ *
* Output: NO (This graph is not bipartite)
*/
public final class BipartiteGraphDFS {
@@ -34,7 +34,7 @@ private BipartiteGraphDFS() {
/**
* Helper method to perform DFS and check if the graph is bipartite.
- *
+ *
* During DFS traversal, this method attempts to color each vertex in such a way
* that no two adjacent vertices share the same color.
*
@@ -44,14 +44,14 @@ private BipartiteGraphDFS() {
* @param node Current vertex being processed
* @return True if the graph (or component of the graph) is bipartite, otherwise false
*/
- private static boolean bipartite(int v, ArrayList
* It uses a bucket queue (implemented here as a List of HashSets) to store vertices,
* where each bucket corresponds to a specific distance from the source. This is more
* efficient than a standard priority queue when the range of edge weights is small.
- *
+ *
* Time Complexity: O(E + W * V), where E is the number of edges, V is the number
* of vertices, and W is the maximum weight of any edge.
*
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java
index 70699a9461f7..4c94929d8bff 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java
@@ -20,7 +20,7 @@ public DijkstraAlgorithm(int vertexCount) {
/**
* Executes Dijkstra's algorithm on the provided graph to find the shortest paths from the source vertex to all other vertices.
- *
+ *
* The graph is represented as an adjacency matrix where {@code graph[i][j]} represents the weight of the edge from vertex {@code i}
* to vertex {@code j}. A value of 0 indicates no edge exists between the vertices.
*
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraOptimizedAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraOptimizedAlgorithm.java
index a686b808a970..8b5ba00834b0 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraOptimizedAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/DijkstraOptimizedAlgorithm.java
@@ -23,7 +23,7 @@ public DijkstraOptimizedAlgorithm(int vertexCount) {
/**
* Executes Dijkstra's algorithm on the provided graph to find the shortest paths from the source vertex to all other vertices.
- *
+ *
* The graph is represented as an adjacency matrix where {@code graph[i][j]} represents the weight of the edge from vertex {@code i}
* to vertex {@code j}. A value of 0 indicates no edge exists between the vertices.
*
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/EdmondsBlossomAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/EdmondsBlossomAlgorithm.java
index db716580d689..76ece5045f11 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/EdmondsBlossomAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/EdmondsBlossomAlgorithm.java
@@ -215,12 +215,12 @@ private static void contractBlossom(BlossomData blossomData) {
* Auxiliary data class to encapsulate common parameters for the blossom operations.
*/
static class BlossomAuxData {
- Queue
* Johnson's algorithm works by using the Bellman-Ford algorithm to compute a transformation of the
* input graph that removes all negative weights, allowing Dijkstra's algorithm to be used for
* efficient shortest path computations.
- *
+ *
* Time Complexity: O(V^2 * log(V) + V*E)
* Space Complexity: O(V^2)
- *
+ *
* Where V is the number of vertices and E is the number of edges in the graph.
/**
* For more information, please visit Johnson's Algorithm
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
index 9a97bc3f4808..eb7e353120c0 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
@@ -17,7 +17,7 @@
*/
class AdjacencyList
* For more information on cuckoo hashing, refer to
* this Wikipedia page.
*/
diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Intersection.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Intersection.java
index 5760d39f1df7..ade05d4075e8 100644
--- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Intersection.java
+++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Intersection.java
@@ -40,7 +40,7 @@ private Intersection() {
/**
* Computes the intersection of two integer arrays, preserving element frequency.
* For example, given [1,2,2,3] and [2,2,4], the result will be [2,2].
- *
+ *
* Steps:
* 1. Count the occurrences of each element in the first array using a map.
* 2. Iterate over the second array and collect common elements.
diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java b/src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java
index 834de9c77881..79c6ad75c28a 100644
--- a/src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java
+++ b/src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java
@@ -196,8 +196,7 @@ public void delete(HeapNode x) {
* @pre heap contains x
*/
private void decreaseKey(HeapNode x, int delta) {
- int newKey = x.getKey() - delta;
- x.key = newKey;
+ x.key = x.getKey() - delta;
if (x.isRoot()) { // no parent to x
this.updateMin(x);
return;
diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/KthElementFinder.java b/src/main/java/com/thealgorithms/datastructures/heaps/KthElementFinder.java
index 7ad92e8ba3c1..5e34a141fe50 100644
--- a/src/main/java/com/thealgorithms/datastructures/heaps/KthElementFinder.java
+++ b/src/main/java/com/thealgorithms/datastructures/heaps/KthElementFinder.java
@@ -17,7 +17,7 @@ private KthElementFinder() {
/**
* Finds the Kth largest element in the given array.
* Uses a min-heap of size K to track the largest K elements.
- *
+ *
* Time Complexity: O(n * log(k)), where n is the size of the input array.
* Space Complexity: O(k), as we maintain a heap of size K.
*
@@ -33,13 +33,13 @@ public static int findKthLargest(int[] nums, int k) {
minHeap.poll();
}
}
- return minHeap.peek();
+ return minHeap.element();
}
/**
* Finds the Kth smallest element in the given array.
* Uses a max-heap of size K to track the smallest K elements.
- *
+ *
* Time Complexity: O(n * log(k)), where n is the size of the input array.
* Space Complexity: O(k), as we maintain a heap of size K.
*
@@ -55,6 +55,6 @@ public static int findKthSmallest(int[] nums, int k) {
maxHeap.poll();
}
}
- return maxHeap.peek();
+ return maxHeap.element();
}
}
diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java b/src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java
index 5b4b29cf1c2d..ffac21e8ec6f 100644
--- a/src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java
+++ b/src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java
@@ -7,12 +7,12 @@
* A Max Heap implementation where each node's key is higher than or equal to its children's keys.
* This data structure provides O(log n) time complexity for insertion and deletion operations,
* and O(1) for retrieving the maximum element.
- *
+ *
* Properties:
* 1. Complete Binary Tree
* 2. Parent node's key ≥ Children nodes' keys
* 3. Root contains the maximum element
- *
+ *
* Example usage:
*
* Time Complexity:
* - Adding a number: O(log n) due to heap insertion.
* - Finding the median: O(1).
- *
+ *
* Space Complexity: O(n), where n is the total number of elements added.
*
* @author Hardvan
*/
public final class MedianFinder {
+
MedianFinder() {
}
@@ -29,8 +31,10 @@ public final class MedianFinder {
*
* @param num the number to be added to the data stream
*/
- public void addNum(int num) {
- if (maxHeap.isEmpty() || num <= maxHeap.peek()) {
+ public void addNum(final int num) {
+ // element() throws NoSuchElementException instead of returning null,
+ // so the null-peek warning is eliminated entirely.
+ if (maxHeap.isEmpty() || num <= maxHeap.element()) {
maxHeap.offer(num);
} else {
minHeap.offer(num);
@@ -49,11 +53,15 @@ public void addNum(int num) {
* median is the middle element from the max-heap.
*
* @return the median of the numbers in the data stream
+ * @throws NoSuchElementException if no numbers have been added yet
*/
public double findMedian() {
+ if (maxHeap.isEmpty()) {
+ throw new NoSuchElementException("Median is undefined for an empty data stream");
+ }
if (maxHeap.size() == minHeap.size()) {
- return (maxHeap.peek() + minHeap.peek()) / 2.0;
+ return (maxHeap.element() + minHeap.element()) / 2.0;
}
- return maxHeap.peek();
+ return maxHeap.element();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/MergeKSortedArrays.java b/src/main/java/com/thealgorithms/datastructures/heaps/MergeKSortedArrays.java
index e41711f05914..de485307afa2 100644
--- a/src/main/java/com/thealgorithms/datastructures/heaps/MergeKSortedArrays.java
+++ b/src/main/java/com/thealgorithms/datastructures/heaps/MergeKSortedArrays.java
@@ -6,10 +6,10 @@
/**
* This class provides a method to merge multiple sorted arrays into a single sorted array.
* It utilizes a min-heap to efficiently retrieve the smallest elements from each array.
- *
+ *
* Time Complexity: O(n * log k), where n is the total number of elements across all arrays
* and k is the number of arrays.
- *
+ *
* Space Complexity: O(k) for the heap, where k is the number of arrays.
*
* @author Hardvan
diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java b/src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java
index 3a4822142b5f..3ab849aee953 100644
--- a/src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java
+++ b/src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java
@@ -7,12 +7,12 @@
* A Min Heap implementation where each node's key is lower than or equal to its children's keys.
* This data structure provides O(log n) time complexity for insertion and deletion operations,
* and O(1) for retrieving the minimum element.
- *
+ *
* Properties:
* 1. Complete Binary Tree
* 2. Parent node's key ≤ Children nodes' keys
* 3. Root contains the minimum element
- *
+ *
* Example usage:
* ```java
* List This implementation includes basic operations such as appending elements
* to the end, removing elements from a specified position, and converting
* the list to a string representation.
- *
* @param
* This implementation includes basic operations such as appending elements to
* the end,
* removing elements from a specified position, and converting the list to a
@@ -18,7 +18,7 @@ public class CircularDoublyLinkedList
* In this specific problem structure, each node has a `next` pointer (to the
* next node at the same level) and a `child` pointer (which points to the head
* of another sorted linked list). The goal is to merge all these lists into a
* single, vertically sorted linked list using the `child` pointer.
- *
+ *
* The approach is a recursive one that leverages a merge utility, similar to
* the merge step in Merge Sort. It recursively flattens the list starting from
* the rightmost node and merges each node's child list with the already
@@ -25,7 +25,7 @@ private FlattenMultilevelLinkedList() {
* reference to the head of a child list.
*/
static class Node {
- int data;
+ final int data;
Node next;
Node child;
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java
index 0f5c50530d92..983d57c73381 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/MergeKSortedLinkedList.java
@@ -23,7 +23,7 @@
*
* This class is designed to handle nodes of integer linked lists and can be expanded for additional data types if needed. This implementation assumes the input lists are already sorted in ascending order. This method does not modify the input list. Reference: https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare Reference: ...'s_tortoise_and_hare Complexity:
* Further information can be found here:
- * https://runestone.academy/ns/books/published/cppds/LinearLinked/ImplementinganOrderedList.html
+ * ...
*
- * Additional contributions made by: PuneetTri(https://github.com/PuneetTri)
+ * Additional contributions made by: PuneetTri(...)
*/
class PriorityQueue {
diff --git a/src/main/java/com/thealgorithms/datastructures/queues/Queue.java b/src/main/java/com/thealgorithms/datastructures/queues/Queue.java
index 046b79a020ed..0ab41d497a67 100644
--- a/src/main/java/com/thealgorithms/datastructures/queues/Queue.java
+++ b/src/main/java/com/thealgorithms/datastructures/queues/Queue.java
@@ -4,7 +4,7 @@
* This class implements a Queue data structure using an array.
* A queue is a first-in-first-out (FIFO) data structure where elements are
* added to the rear and removed from the front.
- *
+ *
* Note: This implementation is not thread-safe.
*/
public final class Queue
* Applications: Computer networks, API rate limiting, distributed systems, etc.
*
* @author Hardvan
diff --git a/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java b/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java
index bbcdfe1cc2a8..66c68f0b09e0 100644
--- a/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java
+++ b/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java
@@ -17,7 +17,7 @@ public class NodeStack This method is a helper for {@link #reverseStack(Stack)}.
- *
+ *
* Steps:
* 1. If the stack is empty, push the element and return.
* 2. Remove the top element from the stack.
diff --git a/src/main/java/com/thealgorithms/datastructures/stacks/StackOfLinkedList.java b/src/main/java/com/thealgorithms/datastructures/stacks/StackOfLinkedList.java
index c12097dfa28c..4cb3889c66c5 100644
--- a/src/main/java/com/thealgorithms/datastructures/stacks/StackOfLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/stacks/StackOfLinkedList.java
@@ -17,7 +17,7 @@ private StackOfLinkedList() {
// A node class for the linked list
class Node {
- public int data;
+ public final int data;
public Node next;
Node(int data) {
@@ -78,7 +78,7 @@ public int pop() {
Node destroy = head;
head = head.next;
int retValue = destroy.data;
- destroy = null; // Help garbage collection
+ // Help garbage collection
size--;
return retValue;
}
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/AVLSimple.java b/src/main/java/com/thealgorithms/datastructures/trees/AVLSimple.java
index 07fc5c87b6c4..ba87106f0ca1 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/AVLSimple.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/AVLSimple.java
@@ -30,7 +30,7 @@ public class AVLSimple {
private class Node {
- int data;
+ final int data;
int height;
Node left;
Node right;
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java b/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java
index 77ee5d5fa23e..27509ee1a16b 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java
@@ -77,7 +77,7 @@ public void delete(int delKey) {
}
// Find the node to be deleted
- Node node = root;
+ Node node;
Node child = root;
while (child != null) {
node = child;
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BSTFromSortedArray.java b/src/main/java/com/thealgorithms/datastructures/trees/BSTFromSortedArray.java
index 1962eaa0a106..a130ee019fff 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/BSTFromSortedArray.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/BSTFromSortedArray.java
@@ -4,7 +4,7 @@
/**
* Given a sorted array. Create a balanced binary search tree from it.
- *
+ *
* Steps: 1. Find the middle element of array. This will act as root 2. Use the
* left half recursively to create left subtree 3. Use the right half
* recursively to create right subtree
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java
index 2c94224ddeb4..0538474a5404 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java
@@ -8,7 +8,6 @@
*
*
* A recursive implementation of generic type BST.
- *
* Reference: Wiki links for BST
*
* Utility class to convert a {@link BinaryTree} into its string representation.
*
* The conversion follows a preorder traversal pattern (root → left → right)
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
index fff84111663b..28adb5fa1fca 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
@@ -5,20 +5,20 @@
/**
* Problem Statement Ceil value for any number x in a collection is a number y
* which is either equal to x or the least greater number than x.
- *
+ *
* Problem: Given a binary search tree containing positive integer values. Find
* ceil value for a given key in O(lg(n)) time. In case if it is not present
* return -1.
- *
+ *
* Ex.1. [30,20,40,10,25,35,50] represents level order traversal of a binary
* search tree. Find ceil for 10. Answer: 20
- *
+ *
* Ex.2. [30,20,40,10,25,35,50] represents level order traversal of a binary
* search tree. Find ceil for 22 Answer: 25
- *
+ *
* Ex.2. [30,20,40,10,25,35,50] represents level order traversal of a binary
* search tree. Find ceil for 52 Answer: -1
- *
+ *
* Solution 1: Brute Force Solution: Do an inorder traversal and save result
* into an array. Iterate over the array to get an element equal to or greater
* than current key. Time Complexity: O(n) Space Complexity: O(n) for auxiliary
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java b/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java
index 17d84bf11d54..4f74c18683cd 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java
@@ -11,7 +11,7 @@
* 2 2
* / \ / \
* 3 4 4 3
- *
+ *
* Below is not symmetric because values is different in last level
* 1
* / \
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
index d4f03078e40b..b644b51aa2fd 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
@@ -19,7 +19,7 @@ public class GenericTree {
private static final class Node {
int data;
- ArrayList
* Complexities:
* Recursive: O(n) - time, O(n) - space, where 'n' is the number of nodes in a tree.
- *
+ *
* Iterative: O(n) - time, O(h) - space, where 'n' is the number of nodes in a tree
* and 'h' is the height of a binary tree.
* In the worst case 'h' can be O(n) if tree is completely unbalanced, for instance:
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java b/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
index 02ff8a5ebdaa..1c6f697fd7e1 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/KDTree.java
@@ -68,7 +68,7 @@ public class KDTree {
static class Point {
- int[] coordinates;
+ final int[] coordinates;
public int getCoordinate(int i) {
return coordinates[i];
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/PreOrderTraversal.java b/src/main/java/com/thealgorithms/datastructures/trees/PreOrderTraversal.java
index 3aceac4d1852..46f82a233a11 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/PreOrderTraversal.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/PreOrderTraversal.java
@@ -8,10 +8,10 @@
/**
* Given tree is traversed in a 'pre-order' way: ROOT -> LEFT -> RIGHT.
* Below are given the recursive and iterative implementations.
- *
+ *
* Complexities:
* Recursive: O(n) - time, O(n) - space, where 'n' is the number of nodes in a tree.
- *
+ *
* Iterative: O(n) - time, O(h) - space, where 'n' is the number of nodes in a tree
* and 'h' is the height of a binary tree.
* In the worst case 'h' can be O(n) if tree is completely unbalanced, for instance:
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java b/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java
index 3ef664f3fa7d..e2d51e892d15 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java
@@ -9,7 +9,7 @@ class TreeNode {
// Members
- int key;
+ final int key;
TreeNode left;
TreeNode right;
@@ -26,8 +26,8 @@ class TreeNode {
// distance of node from root
class QItem {
- TreeNode node;
- int hd;
+ final TreeNode node;
+ final int hd;
QItem(TreeNode n, int h) {
node = n;
@@ -38,7 +38,7 @@ class QItem {
// Class for a Binary Tree
class Tree {
- TreeNode root;
+ final TreeNode root;
// Constructors
Tree() {
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java b/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
index 7652d2197eb8..e55d4e238243 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/QuadTree.java
@@ -10,8 +10,8 @@
* @author Sailok Chinta
*/
class Point {
- public double x;
- public double y;
+ public final double x;
+ public final double y;
Point(double x, double y) {
this.x = x;
@@ -26,8 +26,8 @@ class Point {
* @author Sailok Chinta
*/
class BoundingBox {
- public Point center;
- public double halfWidth;
+ public final Point center;
+ public final double halfWidth;
BoundingBox(Point center, double halfWidth) {
this.center = center;
@@ -59,7 +59,7 @@ public boolean intersectsBoundingBox(BoundingBox otherBoundingBox) {
/**
* QuadTree is a tree data structure that is used to store spatial information
* in an efficient way.
- *
+ *
* This implementation is specific to Point QuadTrees
*
* @see Quad Tree
@@ -128,11 +128,7 @@ public boolean insert(Point point) {
return true;
}
- if (southEast.insert(point)) {
- return true;
- }
-
- return false;
+ return southEast.insert(point);
}
/**
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java b/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java
index 01222b739ff0..60acf01d2b76 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java
@@ -12,7 +12,7 @@ public class RedBlackBST {
private class Node {
- int key = -1;
+ int key;
int color = BLACK;
Node left = nil;
Node right = nil;
@@ -95,7 +95,7 @@ private void insert(Node node) {
private void fixTree(Node node) {
while (node.p.color == RED) {
- Node y = nil;
+ Node y;
if (node.p == node.p.p.left) {
y = node.p.p.right;
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/SameTreesCheck.java b/src/main/java/com/thealgorithms/datastructures/trees/SameTreesCheck.java
index cff27c12f1ca..fff2b9c53a4a 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/SameTreesCheck.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/SameTreesCheck.java
@@ -52,12 +52,12 @@ public static boolean check(BinaryTree.Node p, BinaryTree.Node q) {
BinaryTree.Node second = q2.poll();
// check that some node can be null
// if the check is true: both nodes are null or both nodes are not null
- if (!equalNodes(first, second)) {
+ if (equalNodes(first, second)) {
return false;
}
if (first != null) {
- if (!equalNodes(first.left, second.left)) {
+ if (equalNodes(first.left, second.left)) {
return false;
}
if (first.left != null) {
@@ -65,7 +65,7 @@ public static boolean check(BinaryTree.Node p, BinaryTree.Node q) {
q2.add(second.left);
}
- if (!equalNodes(first.right, second.right)) {
+ if (equalNodes(first.right, second.right)) {
return false;
}
if (first.right != null) {
@@ -79,11 +79,11 @@ public static boolean check(BinaryTree.Node p, BinaryTree.Node q) {
private static boolean equalNodes(BinaryTree.Node p, BinaryTree.Node q) {
if (p == null && q == null) {
- return true;
+ return false;
}
if (p == null || q == null) {
- return false;
+ return true;
}
- return p.data == q.data;
+ return p.data != q.data;
}
}
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree2D.java b/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree2D.java
index 40b9e8a73533..428ee150debc 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree2D.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree2D.java
@@ -4,7 +4,7 @@
* 2D Segment Tree (Tree of Trees) implementation.
* This data structure supports point updates and submatrix sum queries
* in a 2D grid. It achieves this by nesting 1D Segment Trees within a 1D Segment Tree.
- *
+ *
* Time Complexity:
* - Build/Initialization: O(N * M)
* - Point Update: O(log N * log M)
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/ThreadedBinaryTree.java b/src/main/java/com/thealgorithms/datastructures/trees/ThreadedBinaryTree.java
index fd8876cecb70..878bb6565b40 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/ThreadedBinaryTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/ThreadedBinaryTree.java
@@ -25,7 +25,7 @@ public final class ThreadedBinaryTree {
private Node root;
private static final class Node {
- int value;
+ final int value;
Node left;
Node right;
boolean leftIsThread;
@@ -58,7 +58,7 @@ public void insert(int value) {
}
Node current = root;
- Node parent = null;
+ Node parent;
while (true) {
parent = current;
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/Treap.java b/src/main/java/com/thealgorithms/datastructures/trees/Treap.java
index 4a9e5534cc45..5f0a0f2929ab 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/Treap.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/Treap.java
@@ -15,20 +15,20 @@ public class Treap {
public static class TreapNode {
/**
* TreapNode class defines the individual nodes in the Treap
- *
+ *
* value -> holds the value of the node.
* Binary Search Tree is built based on value.
- *
+ *
* priority -> holds the priority of the node.
* Heaps are maintained based on priority.
* It is randomly assigned
- *
+ *
* size -> holds the size of the subtree with current node as root
- *
+ *
* left -> holds the left subtree
* right -> holds the right subtree
*/
- public int value;
+ public final int value;
private final int priority;
private int size;
public TreapNode left;
@@ -65,7 +65,7 @@ private void updateSize() {
/**
* Constructors
- *
+ *
* Treap() -> create an empty Treap
* Treap(int[] nodeValues) -> add the elements given in the array to the Treap
*/
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java b/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java
index cf56731fb079..7b35a8c68238 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java
@@ -34,9 +34,9 @@ private final class Node {
}
// Using an arraylist to store the inorder traversal of the given binary tree
- static ArrayList
* All known subclasses: {@link TreeNode}, {@link SimpleNode}.
*
* @param
* All known subclasses: {@link SimpleTreeNode}, {@link LargeTreeNode}.
*
* @param
* Problem: Given two strings, `a` and `b`, determine if string `a` can be
* transformed into string `b` by performing the following operations:
* 1. Capitalize zero or more of `a`'s lowercase letters (i.e., convert them to uppercase).
* 2. Delete any of the remaining lowercase letters from `a`.
- *
+ *
* The task is to determine whether it is possible to make string `a` equal to string `b`.
*
* @author Hardvan
@@ -24,7 +24,7 @@ private Abbreviation() {
* @param b The target string containing only uppercase letters.
* @return {@code true} if string `a` can be transformed into string `b`,
* {@code false} otherwise.
- *
+ *
* Time Complexity: O(n * m) where n = length of string `a` and m = length of string `b`.
* Space Complexity: O(n * m) due to the dynamic programming table.
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/AllConstruct.java b/src/main/java/com/thealgorithms/dynamicprogramming/AllConstruct.java
index e7712b13a2b7..b7b2be19f2d4 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/AllConstruct.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/AllConstruct.java
@@ -5,7 +5,7 @@
/**
* This class provides a solution to the "All Construct" problem.
- *
+ *
* The problem is to determine all the ways a target string can be constructed
* from a given list of substrings. Each substring in the word bank can be used
* multiple times, and the order of substrings matters.
@@ -21,7 +21,7 @@ private AllConstruct() {
* from the given word bank.
* Time Complexity: O(n * m * k), where n = length of the target,
* m = number of words in wordBank, and k = average length of a word.
- *
+ *
* Space Complexity: O(n * m) due to the size of the table storing combinations.
*
* @param target The target string to construct.
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
index ccd54ee4349a..57a65989d338 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
@@ -2,7 +2,7 @@
/**
* Java program for Boundary fill algorithm.
- * @author Akshay Dubey (https://github.com/itsAkshayDubey)
+ * @author Akshay Dubey (...)
*/
public final class BoundaryFill {
private BoundaryFill() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
index d01066f611bd..b2a78b94ceb2 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
@@ -4,7 +4,7 @@
/**
* This file contains an implementation of finding the nth CATALAN NUMBER using
* dynamic programming : Wikipedia
- *
+ *
* Time Complexity: O(n^2) Space Complexity: O(n)
*
* @author AMRITESH ANAND
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java b/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
index 7edc9603dc8b..6c8c7378ad1e 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
@@ -1,7 +1,7 @@
package com.thealgorithms.dynamicprogramming;
/**
- * @author Varun Upadhyay (https://github.com/varunu28)
+ * @author Varun Upadhyay (...)
*/
public final class CoinChange {
private CoinChange() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/DamerauLevenshteinDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/DamerauLevenshteinDistance.java
index 9721d4ab0ad5..ba7520fb1078 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/DamerauLevenshteinDistance.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/DamerauLevenshteinDistance.java
@@ -5,14 +5,14 @@
/**
* Implementation of the full Damerau–Levenshtein distance algorithm.
- *
+ *
* This algorithm calculates the minimum number of operations required
* to transform one string into another. Supported operations are:
* insertion, deletion, substitution, and transposition of adjacent characters.
- *
+ *
* Unlike the restricted version (OSA), this implementation allows multiple
* edits on the same substring, computing the true edit distance.
- *
+ *
* Time Complexity: O(n * m * max(n, m))
* Space Complexity: O(n * m)
*/
@@ -60,7 +60,7 @@ private static void validateInputs(String s1, String s2) {
/**
* Builds a character map containing all unique characters from both strings.
* Each character is initialized with a position value of 0.
- *
+ *
* This map is used to track the last occurrence position of each character
* during the distance computation, which is essential for handling transpositions.
*
@@ -81,11 +81,11 @@ private static Map
* The table has dimensions (n+2) x (m+2) where n and m are the lengths
* of the input strings. The extra rows and columns are used to handle
* the transposition operation correctly.
- *
+ *
* The first row and column are initialized with the maximum possible distance,
* while the second row and column represent the base case of transforming
* from an empty string.
@@ -116,11 +116,11 @@ private static int[][] initializeTable(int n, int m) {
/**
* Fills the dynamic programming table by computing the minimum edit distance
* for each substring pair.
- *
+ *
* This method implements the core algorithm logic, iterating through both strings
* and computing the minimum cost of transforming substrings. It considers all
* four operations: insertion, deletion, substitution, and transposition.
- *
+ *
* The character position map is updated as we progress through the first string
* to enable efficient transposition cost calculation.
*
@@ -156,13 +156,13 @@ private static void fillTable(String s1, String s2, int[][] dp, Map
* The transposition cost accounts for the gap between the current position
* and the last position where matching characters were found.
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/DigitDP.java b/src/main/java/com/thealgorithms/dynamicprogramming/DigitDP.java
index 7dae7603fedc..f549bf4f2ee6 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/DigitDP.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/DigitDP.java
@@ -61,7 +61,7 @@ private static long countWithDigitSum(long number, int target) {
/**
* Recursive memoized function to explore digit placements.
- *
+ *
* Time Complexity: O(number_of_digits * target_sum * 10)
* Space Complexity: O(number_of_digits * target_sum * 2)
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
index 0d6aff2bbef3..045d62b42b19 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
@@ -4,7 +4,7 @@
import java.util.Map;
/**
- * @author Varun Upadhyay (https://github.com/varunu28)
+ * @author Varun Upadhyay (...)
*/
public final class Fibonacci {
private Fibonacci() {
@@ -76,7 +76,7 @@ public static int fibBotUp(int n) {
*
* Whereas , the above functions will take O(n) Space.
* @throws IllegalArgumentException if n is negative
- * @author Shoaib Rayeen (https://github.com/shoaibrayeen)
+ * @author Shoaib Rayeen (...)
*/
public static int fibOptimized(int n) {
if (n < 0) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
index 7a0a3da94c1e..8cef4bfa36ae 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
@@ -4,7 +4,7 @@
* This class implements Kadane's Algorithm to find the maximum subarray sum
* within a given array of integers. The algorithm efficiently computes the maximum
* sum of a contiguous subarray in linear time.
- *
+ *
* Author: Siddhant Swarup Mallick
*/
public final class KadaneAlgorithm {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java b/src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java
index 0d4c8d501f9f..5ca5714f809f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/Knapsack.java
@@ -4,14 +4,11 @@
/**
* 0/1 Knapsack Problem - Dynamic Programming solution.
- *
* This algorithm solves the classic optimization problem where we have n items,
* each with a weight and a value. The goal is to maximize the total value
* without exceeding the knapsack's weight capacity.
- *
* Time Complexity: O(n * W)
* Space Complexity: O(W)
- *
* Example:
* values = {60, 100, 120}
* weights = {10, 20, 30}
@@ -64,7 +61,7 @@ public static int knapSack(final int weightCapacity, final int[] weights, final
return dp[weightCapacity];
}
- /*
+
// Example main method for local testing only.
public static void main(String[] args) {
int[] values = {60, 100, 120};
@@ -74,5 +71,5 @@ public static void main(String[] args) {
int maxValue = knapSack(weightCapacity, weights, values);
System.out.println("Maximum value = " + maxValue); // Output: 220
}
- */
+
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOne.java b/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOne.java
index abc1e321ca8f..cee0edb9bac5 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOne.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOne.java
@@ -4,11 +4,11 @@
* The {@code KnapsackZeroOne} provides Recursive solution for the 0/1 Knapsack
* problem. Solves by exploring all combinations of items using recursion. No
* memoization or dynamic programming optimizations are applied.
- *
+ *
* Time Complexity: O(2^n) — explores all subsets.
* Space Complexity: O(n) — due to recursive call stack.
- *
- * Problem Reference: https://en.wikipedia.org/wiki/Knapsack_problem
+ *
+ * Problem Refhttps://en.wikipedia.org/wiki/Knapsack_problem
*/
public final class KnapsackZeroOne {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOneTabulation.java b/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOneTabulation.java
index c560efc61c71..62b5ad53618f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOneTabulation.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackZeroOneTabulation.java
@@ -5,18 +5,18 @@
* This method uses dynamic programming to build up a solution iteratively,
* filling a 2-D array where each entry dp[i][w] represents the maximum value
* achievable with the first i items and a knapsack capacity of w.
- *
+ *
* The tabulation approach is efficient because it avoids redundant calculations
* by solving all subproblems in advance and storing their results, ensuring
* each subproblem is solved only once. This is a key technique in dynamic programming,
* making it possible to solve problems that would otherwise be infeasible due to
* exponential time complexity in naive recursive solutions.
- *
+ *
* Time Complexity: O(n * W), where n is the number of items and W is the knapsack capacity.
* Space Complexity: O(n * W) for the DP table.
- *
- * For more information, see:
- * https://en.wikipedia.org/wiki/Knapsack_problem#Dynamic_programming
+ *
+ * For more informatisee:
+ * https://en.wikipedia.org/wiki/Knapsack_problem#Dynamic_programming
*/
public final class KnapsackZeroOneTabulation {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java
index 119d65dfe365..41c82d37c827 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java
@@ -4,7 +4,7 @@
/**
* Provides functions to calculate the Levenshtein distance between two strings.
- *
+ *
* The Levenshtein distance is a measure of the similarity between two strings by calculating the minimum number of single-character
* edits (insertions, deletions, or substitutions) required to change one string into the other.
*/
@@ -14,19 +14,19 @@ private LevenshteinDistance() {
/**
* Calculates the Levenshtein distance between two strings using a naive dynamic programming approach.
- *
+ *
* This function computes the Levenshtein distance by constructing a dynamic programming matrix and iteratively filling it in.
* It follows the standard top-to-bottom, left-to-right approach for filling in the matrix.
*
* @param string1 The first string.
* @param string2 The second string.
* @return The Levenshtein distance between the two input strings.
- *
+ *
* Time complexity: O(nm),
* Space complexity: O(nm),
- *
+ *
* where n and m are lengths of `string1` and `string2`.
- *
+ *
* Note that this implementation uses a straightforward dynamic programming approach without any space optimization.
* It may consume more memory for larger input strings compared to the optimized version.
*/
@@ -43,18 +43,18 @@ public static int naiveLevenshteinDistance(final String string1, final String st
/**
* Calculates the Levenshtein distance between two strings using an optimized dynamic programming approach.
- *
+ *
* This edit distance is defined as 1 point per insertion, substitution, or deletion required to make the strings equal.
*
* @param string1 The first string.
* @param string2 The second string.
* @return The Levenshtein distance between the two input strings.
- *
+ *
* Time complexity: O(nm),
* Space complexity: O(n),
- *
+ *
* where n and m are lengths of `string1` and `string2`.
- *
+ *
* Note that this implementation utilizes an optimized dynamic programming approach, significantly reducing the space complexity from O(nm) to O(n), where n and m are the lengths of `string1` and `string2`.
*
* Additionally, it minimizes space usage by leveraging the shortest string horizontally and the longest string vertically in the computation matrix.
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
index ba1def551192..d55af13c89e5 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
@@ -9,7 +9,7 @@ private LongestArithmeticSubsequence() {
/**
* Returns the length of the longest arithmetic subsequence in the given array.
- *
+ *
* A sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value
* (for 0 <= i < seq.length - 1).
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java
index 54837b5f4e71..d123c65321e7 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java
@@ -5,7 +5,7 @@
* The LCS of two sequences is the longest sequence that appears in both
* sequences
* in the same order, but not necessarily consecutively.
- *
+ *
* This implementation uses dynamic programming to find the LCS of two strings.
*/
final class LongestCommonSubsequence {
@@ -26,7 +26,7 @@ public static String getLCS(String str1, String str2) {
return null;
}
// If either string is empty, return an empty string as LCS.
- if (str1.length() == 0 || str2.length() == 0) {
+ if (str1.isEmpty() || str2.isEmpty()) {
return "";
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java
index 470833ce9c97..b08b858da67f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java
@@ -1,7 +1,7 @@
package com.thealgorithms.dynamicprogramming;
/**
- * @author Afrizal Fikri (https://github.com/icalF)
+ * @author Afrizal Fikri (...)
*/
public final class LongestIncreasingSubsequence {
private LongestIncreasingSubsequence() {
@@ -53,7 +53,7 @@ else if (array[i] > tail[length - 1]) {
}
/**
- * @author Alon Firestein (https://github.com/alonfirestein)
+ * @author Alon Firestein (...)
*/
// A function for finding the length of the LIS algorithm in O(nlogn) complexity.
public static int findLISLen(int[] a) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceNLogN.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceNLogN.java
index 7bc0855e0566..47e70b6adb6b 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceNLogN.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceNLogN.java
@@ -4,7 +4,7 @@
* Implementation of the Longest Increasing Subsequence (LIS) problem using
* an O(n log n) dynamic programming solution enhanced with binary search.
*
- * @author Vusal Huseynov (https://github.com/huseynovvusal)
+ * @author Vusal Huseynov (...)
*/
public final class LongestIncreasingSubsequenceNLogN {
private LongestIncreasingSubsequenceNLogN() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java
index 02696bfca9c2..e717cc674a86 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java
@@ -4,7 +4,7 @@
* Given a string containing just the characters '(' and ')', find the length of
* the longest valid (well-formed) parentheses substring.
*
- * @author Libin Yang (https://github.com/yanglbme)
+ * @author Libin Yang (...)
* @since 2018/10/5
*/
public final class LongestValidParentheses {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java b/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
index 49af3ae3db88..1118b494c533 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
@@ -4,7 +4,7 @@
* Class to find the maximum sum of non-adjacent elements in an array. This
* class contains two approaches: one with O(n) space complexity and another
* with O(1) space optimization. For more information, refer to
- * https://takeuforward.org/data-structure/maximum-sum-of-non-adjacent-elements-dp-5/
+ * ...
*/
final class MaximumSumOfNonAdjacentElements {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/NeedlemanWunsch.java b/src/main/java/com/thealgorithms/dynamicprogramming/NeedlemanWunsch.java
index 13b640cf0d04..7247ebe7cca7 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/NeedlemanWunsch.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/NeedlemanWunsch.java
@@ -4,7 +4,7 @@
* The Needleman–Wunsch algorithm performs global sequence alignment between two strings.
* It computes the optimal alignment score using dynamic programming,
* given a scoring scheme for matches, mismatches, and gaps.
- *
+ *
* Time Complexity: O(n * m)
* Space Complexity: O(n * m)
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalBinarySearchTree.java b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalBinarySearchTree.java
index 428176ea6c40..6064e1e2c49c 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalBinarySearchTree.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalBinarySearchTree.java
@@ -13,7 +13,7 @@
* and 10 as its left child. The total cost is 50 * 1 + 34 * 2 = 118.
*
* Reference:
- * https://en.wikipedia.org/wiki/Optimal_binary_search_tree
+ * ...
*/
public final class OptimalBinarySearchTree {
private OptimalBinarySearchTree() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
index e31bb73096e8..bc347350f55e 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
@@ -4,8 +4,8 @@
* This class refers to the Optimal Job Scheduling problem with the following constrains:
* - precedence relation between the processes
* - machine pair dependent transportation delays
- *
- * https://en.wikipedia.org/wiki/Optimal_job_scheduling
+ * * https://en.wikipedia.org/wiki/Optimal_job_scheduling
*
* @author georgioct@csd.auth.gr
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java b/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
index 8c72fa347f50..ef3ab5d508c2 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
@@ -2,11 +2,11 @@
import java.util.Arrays;
/**
* @author Md Asif Joardar
- *
+ *
* Description: The partition problem is a classic problem in computer science
* that asks whether a given set can be partitioned into two subsets such that
* the sum of elements in each subset is the same.
- *
+ *
* Example:
* Consider nums = {1, 2, 3}
* We can split the array "nums" into two partitions, where each having a sum of 3.
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
index 181ac72a654d..97262eb73792 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
@@ -5,11 +5,11 @@
* algorithm that finds if wildcard is matched with text. The matching should
* cover the entire text ?-> matches single characters *-> match the sequence of
* characters
- *
+ *
* For calculation of Time and Space Complexity. Let N be length of src and M be length of pat
- *
- * Memoization vs Tabulation : https://www.geeksforgeeks.org/tabulation-vs-memoization/
- * Question Link : https://practice.geeksforgeeks.org/problems/wildcard-pattern-matching/1
+ *
+ * Memoization vs Tabul: https://www.geeksforgeeks.org/tabulation-vs-memoization/
+ * Question...tching/1
*/
public final class RegexMatching {
private RegexMatching() {
@@ -19,7 +19,7 @@ private RegexMatching() {
* Method 1: Determines if the given source string matches the given pattern using a recursive approach.
* This method directly applies recursion to check if the source string matches the pattern, considering
* the wildcards '?' and '*'.
- *
+ *
* Time Complexity: O(2^(N+M)), where N is the length of the source string and M is the length of the pattern.
* Space Complexity: O(N + M) due to the recursion stack.
*
@@ -28,13 +28,13 @@ private RegexMatching() {
* @return {@code true} if the source string matches the pattern, {@code false} otherwise.
*/
public static boolean regexRecursion(String src, String pat) {
- if (src.length() == 0 && pat.length() == 0) {
+ if (src.isEmpty() && pat.isEmpty()) {
return true;
}
- if (src.length() != 0 && pat.length() == 0) {
+ if (!src.isEmpty() && pat.isEmpty()) {
return false;
}
- if (src.length() == 0 && pat.length() != 0) {
+ if (src.isEmpty() && !pat.isEmpty()) {
for (int i = 0; i < pat.length(); i++) {
if (pat.charAt(i) != '*') {
return false;
@@ -64,7 +64,7 @@ public static boolean regexRecursion(String src, String pat) {
/**
* Method 2: Determines if the given source string matches the given pattern using recursion.
* This method utilizes a virtual index for both the source string and the pattern to manage the recursion.
- *
+ *
* Time Complexity: O(2^(N+M)) where N is the length of the source string and M is the length of the pattern.
* Space Complexity: O(N + M) due to the recursion stack.
*
@@ -108,7 +108,7 @@ static boolean regexRecursion(String src, String pat, int svidx, int pvidx) {
/**
* Method 3: Determines if the given source string matches the given pattern using top-down dynamic programming (memoization).
* This method utilizes memoization to store intermediate results, reducing redundant computations and improving efficiency.
- *
+ *
* Time Complexity: O(N * M), where N is the length of the source string and M is the length of the pattern.
* Space Complexity: O(N * M) for the memoization table, plus additional space for the recursion stack.
*
@@ -158,7 +158,7 @@ public static boolean regexRecursion(String src, String pat, int svidx, int pvid
* Method 4: Determines if the given source string matches the given pattern using bottom-up dynamic programming (tabulation).
* This method builds a solution iteratively by filling out a table, where each cell represents whether a substring
* of the source string matches a substring of the pattern.
- *
+ *
* Time Complexity: O(N * M), where N is the length of the source string and M is the length of the pattern.
* Space Complexity: O(N * M) for the table used in the tabulation process.
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SmithWaterman.java b/src/main/java/com/thealgorithms/dynamicprogramming/SmithWaterman.java
index c0d66f68b502..69ca7e42dddd 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SmithWaterman.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SmithWaterman.java
@@ -3,7 +3,7 @@
/**
* Smith–Waterman algorithm for local sequence alignment.
* Finds the highest scoring local alignment between substrings of two sequences.
- *
+ *
* Time Complexity: O(n * m)
* Space Complexity: O(n * m)
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
index e9c15c1b4f24..478d711c3036 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
@@ -3,11 +3,11 @@
/**
* A utility class that contains the Sum of Subset problem solution using
* recursion.
- *
+ *
* The Sum of Subset problem determines whether a subset of elements from a
* given array sums up to a specific target value.
- *
- * Wikipedia: https://en.wikipedia.org/wiki/Subset_sum_problem
+ *
+ * Wikhttps://en.wikipedia.org/wiki/Subset_sum_problem
*/
public final class SumOfSubset {
@@ -22,7 +22,7 @@ private SumOfSubset() {
* @param num The index of the current element being considered.
* @param key The target sum we are trying to achieve.
* @return true if a subset of `arr` adds up to `key`, false otherwise.
- *
+ *
* This is a recursive solution that checks for two possibilities at
* each step:
* 1. Include the current element in the subset and check if the
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/TreeMatching.java b/src/main/java/com/thealgorithms/dynamicprogramming/TreeMatching.java
index 9fd82ccaf078..4448b6ed8a72 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/TreeMatching.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/TreeMatching.java
@@ -5,7 +5,7 @@
/**
* This class implements the algorithm for calculating the maximum weighted matching in a tree.
* The tree is represented as an undirected graph with weighted edges.
- *
+ *
* Problem Description:
* Given an undirected tree G = (V, E) with edge weights γ: E → N and a root r ∈ V,
* the goal is to find a maximum weight matching M ⊆ E such that no two edges in M
@@ -16,8 +16,8 @@
*/
public class TreeMatching {
- private UndirectedAdjacencyListGraph graph;
- private int[][] dp;
+ private final UndirectedAdjacencyListGraph graph;
+ private final int[][] dp;
/**
* Constructor that initializes the graph and the DP table.
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java b/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java
index 3ff6cc620236..71b3e69bb2ba 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java
@@ -2,7 +2,7 @@
/**
* The {@code Tribonacci} class provides a method to compute the n-th number in the Tribonacci sequence.
- * N-th Tribonacci Number - https://leetcode.com/problems/n-th-tribonacci-number/description/
+ * N-th Tribonacci Number - ...
*/
public final class Tribonacci {
private Tribonacci() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java b/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java
index 22ad8a7dd8e3..197e2a5d5a13 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java
@@ -4,7 +4,7 @@
/**
* Author: Siddhant Swarup Mallick
- * Github: https://github.com/siddhant2002
+ * Github: ...
*
* Problem Description:
* A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java b/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
index 8c7ea6179e3f..a13725532812 100755
--- a/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
@@ -12,7 +12,7 @@
* using dynamic programming and recursion. It ensures that duplicate characters
* are not counted multiple times in the subsequences. Author: https://github.com/Tuhinm2002 Author: ...
* Use DP to return True if the pattern matches the entire text and False otherwise
*
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java b/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
index 022b43184a88..72ddc2a9f2b3 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
@@ -5,19 +5,19 @@
* Given a collection of N wines with different prices, the objective is to maximize profit by selling
* one wine each year, considering the constraint that only the leftmost or rightmost wine can be sold
* at any given time.
- *
+ *
* The price of the ith wine is pi, and the selling price increases by a factor of the year in which
* it is sold. This class implements three approaches to solve the problem:
- *
+ *
* 1. **Recursion**: A straightforward recursive method that computes the maximum profit.
* - Time Complexity: O(2^N)
* - Space Complexity: O(N) due to recursive calls.
- *
+ *
* 2. **Top-Down Dynamic Programming (Memoization)**: This approach caches the results of subproblems
* to avoid redundant computations.
* - Time Complexity: O(N^2)
* - Space Complexity: O(N^2) for the storage of results and O(N) for recursion stack.
- *
+ *
* 3. **Bottom-Up Dynamic Programming (Tabulation)**: This method builds a table iteratively to
* compute the maximum profit for all possible subproblems.
* - Time Complexity: O(N^2)
diff --git a/src/main/java/com/thealgorithms/geometry/DDALine.java b/src/main/java/com/thealgorithms/geometry/DDALine.java
index a084ac5a9277..7dd288f4c5ea 100644
--- a/src/main/java/com/thealgorithms/geometry/DDALine.java
+++ b/src/main/java/com/thealgorithms/geometry/DDALine.java
@@ -8,7 +8,7 @@
* The {@code DDALine} class implements the Digital Differential Analyzer (DDA)
* line drawing algorithm. It computes points along a line between two given
* endpoints using floating-point arithmetic.
- *
+ *
* The algorithm is straightforward but less efficient compared to
* Bresenham’s line algorithm, since it relies on floating-point operations.
/**
diff --git a/src/main/java/com/thealgorithms/geometry/GrahamScan.java b/src/main/java/com/thealgorithms/geometry/GrahamScan.java
index 1a373cf315a2..b2b74d43e103 100644
--- a/src/main/java/com/thealgorithms/geometry/GrahamScan.java
+++ b/src/main/java/com/thealgorithms/geometry/GrahamScan.java
@@ -9,11 +9,11 @@
* The time complexity is O(n) in the best case and O(n log(n)) in the worst case.
* The space complexity is O(n).
* This algorithm is applicable only to integral coordinates.
- *
- * References:
- * https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/geometry/graham_scan_algorithm.cpp
- * https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/geometry/graham_scan_functions.hpp
- * https://algs4.cs.princeton.edu/99hull/GrahamScan.java.html
+ *
+ * References:* https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/geometry/graham_scan_algorithm.cpp* https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/geometry/graham_scan_functions.hpp* https://algs4.cs.princeton.edu/99hull/GrahamScan.java.html
*/
public class GrahamScan {
diff --git a/src/main/java/com/thealgorithms/geometry/Haversine.java b/src/main/java/com/thealgorithms/geometry/Haversine.java
index fa1799e9f076..8279521817a6 100644
--- a/src/main/java/com/thealgorithms/geometry/Haversine.java
+++ b/src/main/java/com/thealgorithms/geometry/Haversine.java
@@ -1,11 +1,11 @@
package com.thealgorithms.geometry;
/**
* This Class implements the Haversine formula to calculate the distance between two points on a sphere (like Earth) from their latitudes and longitudes.
- *
+ *
* The Haversine formula is used in navigation and mapping to find the great-circle distance,
* which is the shortest distance between two points along the surface of a sphere. It is often
* used to calculate the "as the crow flies" distance between two geographical locations.
- *
+ *
* The formula is reliable for all distances, including small ones, and avoids issues with
* numerical instability that can affect other methods.
*
diff --git a/src/main/java/com/thealgorithms/geometry/LineIntersection.java b/src/main/java/com/thealgorithms/geometry/LineIntersection.java
index 8d65833816b3..4f82cf0fac0b 100644
--- a/src/main/java/com/thealgorithms/geometry/LineIntersection.java
+++ b/src/main/java/com/thealgorithms/geometry/LineIntersection.java
@@ -38,11 +38,7 @@ public static boolean intersects(Point p1, Point p2, Point q1, Point q2) {
if (o3 == 0 && onSegment(q1, p1, q2)) {
return true;
}
- if (o4 == 0 && onSegment(q1, p2, q2)) {
- return true;
- }
-
- return false;
+ return o4 == 0 && onSegment(q1, p2, q2);
}
/**
diff --git a/src/main/java/com/thealgorithms/geometry/WusLine.java b/src/main/java/com/thealgorithms/geometry/WusLine.java
index 3539daaf6e5a..f4794e5ce9a4 100644
--- a/src/main/java/com/thealgorithms/geometry/WusLine.java
+++ b/src/main/java/com/thealgorithms/geometry/WusLine.java
@@ -8,16 +8,16 @@
* The {@code WusLine} class implements Xiaolin Wu's line drawing algorithm,
* which produces anti-aliased lines by varying pixel brightness
* according to the line's proximity to pixel centers.
- *
+ *
* This implementation returns the pixel coordinates along with
* their associated intensity values (in range [0.0, 1.0]), allowing
* rendering systems to blend accordingly.
- *
+ *
* The algorithm works by:
* - Computing a line's intersection with pixel boundaries
* - Assigning intensity values based on distance from pixel centers
* - Drawing pairs of pixels perpendicular to the line's direction
- *
+ *
* Reference: Xiaolin Wu, "An Efficient Antialiasing Technique",
* Computer Graphics (SIGGRAPH '91 Proceedings).
*
@@ -30,7 +30,7 @@ private WusLine() {
/**
* Represents a pixel and its intensity for anti-aliased rendering.
- *
+ *
* The intensity value determines how bright the pixel should be drawn,
* with 1.0 being fully opaque and 0.0 being fully transparent.
*/
@@ -73,7 +73,7 @@ private static class EndpointData {
/**
* Draws an anti-aliased line using Wu's algorithm.
- *
+ *
* The algorithm produces smooth lines by drawing pairs of pixels at each
* x-coordinate (or y-coordinate for steep lines), with intensities based on
* the line's distance from pixel centers.
diff --git a/src/main/java/com/thealgorithms/graph/EdmondsKarp.java b/src/main/java/com/thealgorithms/graph/EdmondsKarp.java
index 59e7b09cb49c..4ca6c2e1d813 100644
--- a/src/main/java/com/thealgorithms/graph/EdmondsKarp.java
+++ b/src/main/java/com/thealgorithms/graph/EdmondsKarp.java
@@ -37,21 +37,7 @@ public static int maxFlow(int[][] capacity, int source, int sink) {
throw new IllegalArgumentException("Capacity matrix must not be null or empty");
}
- final int n = capacity.length;
- for (int row = 0; row < n; row++) {
- if (capacity[row] == null || capacity[row].length != n) {
- throw new IllegalArgumentException("Capacity matrix must be square");
- }
- for (int col = 0; col < n; col++) {
- if (capacity[row][col] < 0) {
- throw new IllegalArgumentException("Capacities must be non-negative");
- }
- }
- }
-
- if (source < 0 || source >= n || sink < 0 || sink >= n) {
- throw new IllegalArgumentException("Source and sink must be valid vertex indices");
- }
+ final int n = getN(capacity, source, sink);
if (source == sink) {
return 0;
}
@@ -83,6 +69,25 @@ public static int maxFlow(int[][] capacity, int source, int sink) {
return maxFlow;
}
+ private static int getN(int[][] capacity, int source, int sink) {
+ final int n = capacity.length;
+ for (int[] ints : capacity) {
+ if (ints == null || ints.length != n) {
+ throw new IllegalArgumentException("Capacity matrix must be square");
+ }
+ for (int col = 0; col < n; col++) {
+ if (ints[col] < 0) {
+ throw new IllegalArgumentException("Capacities must be non-negative");
+ }
+ }
+ }
+
+ if (source < 0 || source >= n || sink < 0 || sink >= n) {
+ throw new IllegalArgumentException("Source and sink must be valid vertex indices");
+ }
+ return n;
+ }
+
private static boolean bfs(int[][] residual, int source, int sink, int[] parent) {
Arrays.fill(parent, -1);
parent[source] = source;
diff --git a/src/main/java/com/thealgorithms/graph/HierholzerEulerianPath.java b/src/main/java/com/thealgorithms/graph/HierholzerEulerianPath.java
index 82da5c8163e5..96e883e33dac 100644
--- a/src/main/java/com/thealgorithms/graph/HierholzerEulerianPath.java
+++ b/src/main/java/com/thealgorithms/graph/HierholzerEulerianPath.java
@@ -7,16 +7,16 @@
import java.util.List;
/**
- * Implementation of Hierholzer's Algorithm for finding an Eulerian Path or Circuit
+ * Implementation of Hierholzer's Algorithm for finding a Eulerian Path or Circuit
* in a directed graph.
*
*
- * An Eulerian Circuit is a path that starts and ends at the same vertex
+ * A Eulerian Circuit is a path that starts and ends at the same vertex
* and visits every edge exactly once.
*
- * An Eulerian Path visits every edge exactly once but may start and end
+ * A Eulerian Path visits every edge exactly once but may start and end
* at different vertices.
*
* Left part: vertices [0,nLeft-1], Right part: [0,nRight-1].
* Adjacency list: for each left vertex u, list right vertices v it connects to.
- *
+ *
* Time complexity: O(E * sqrt(V)).
*
* @see
diff --git a/src/main/java/com/thealgorithms/graph/StoerWagner.java b/src/main/java/com/thealgorithms/graph/StoerWagner.java
index b204834c431a..e0985bc038c0 100644
--- a/src/main/java/com/thealgorithms/graph/StoerWagner.java
+++ b/src/main/java/com/thealgorithms/graph/StoerWagner.java
@@ -4,8 +4,8 @@
* An implementation of the Stoer-Wagner algorithm to find the global minimum cut of an undirected, weighted graph.
* A minimum cut is a partition of the graph's vertices into two disjoint sets with the minimum possible edge weight
* sum connecting the two sets.
- *
- * Wikipedia: https://en.wikipedia.org/wiki/Stoer%E2%80%93Wagner_algorithm
+ *
+ * Wikipedhttps://en.wikipedia.org/wiki/Stoer%E2%80%93Wagner_algorithm
* Time Complexity: O(V^3) where V is the number of vertices.
*/
public class StoerWagner {
diff --git a/src/main/java/com/thealgorithms/graph/TarjanBridges.java b/src/main/java/com/thealgorithms/graph/TarjanBridges.java
index dbe2e710429a..427e362631e5 100644
--- a/src/main/java/com/thealgorithms/graph/TarjanBridges.java
+++ b/src/main/java/com/thealgorithms/graph/TarjanBridges.java
@@ -80,7 +80,7 @@ private static class BridgeFinder {
private final List References:
- * - Wikipedia: Yen's algorithm (https://en.wikipedia.org/wiki/Yen%27s_algorithm)
+ * - Wikipedia: Yen's algorithm (...)
* - Dijkstra's algorithm for the base shortest path computation. References:
*
* The goal is to select the maximum number of activities that don't overlap
* with each other, based on their start and end times. Activities are chosen
* such that no two selected activities overlap.
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
index 9535a7c6190e..816b7ecb7c00 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
@@ -7,12 +7,12 @@
* The FractionalKnapsack class provides a method to solve the fractional knapsack problem
* using a greedy algorithm approach. It allows for selecting fractions of items to maximize
* the total value in a knapsack with a given weight capacity.
- *
+ *
* The problem consists of a set of items, each with a weight and a value, and a knapsack
* that can carry a maximum weight. The goal is to maximize the value of items in the knapsack,
* allowing for the inclusion of fractions of items.
- *
- * Problem Link: https://en.wikipedia.org/wiki/Continuous_knapsack_problem
+ *
+ * ProbleLink: https://en.wikipedia.org/wiki/Continuous_knapsack_problem
*/
public final class FractionalKnapsack {
private FractionalKnapsack() {
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/GaleShapley.java b/src/main/java/com/thealgorithms/greedyalgorithms/GaleShapley.java
index a4a0366375eb..79bd1071d106 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/GaleShapley.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/GaleShapley.java
@@ -6,7 +6,7 @@
/**
* Implementation of the Gale-Shapley Algorithm for Stable Matching.
- * Problem link: https://en.wikipedia.org/wiki/Stable_marriage_problem
+ * Problem link: ...
*/
public final class GaleShapley {
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java b/src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java
index ceb664a31e8a..b16b58866a41 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/JobSequencing.java
@@ -11,9 +11,9 @@ private JobSequencing() {
// Define a Job class that implements Comparable for sorting by profit in descending order
static class Job implements Comparable
* Merge all overlapping intervals and return an array of the non-overlapping
* intervals
* that cover all the intervals in the input.
@@ -22,7 +22,7 @@ private MergeIntervals() {
/**
* Merges overlapping intervals from the given array of intervals.
- *
+ *
* The method sorts the intervals by their start time, then iterates through the
* sorted intervals
* and merges overlapping intervals. If an interval overlaps with the last
@@ -33,7 +33,7 @@ private MergeIntervals() {
* @param intervals A 2D array representing intervals where each element is an
* interval [starti, endi].
* @return A 2D array of merged intervals where no intervals overlap.
- *
+ *
* Example:
* Input: {{1, 3}, {2, 6}, {8, 10}, {15, 18}}
* Output: {{1, 6}, {8, 10}, {15, 18}}
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java b/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java
index c7f219ef3eab..ec6c8aef6d12 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/MinimizingLateness.java
@@ -7,11 +7,11 @@ private MinimizingLateness() {
}
public static class Job {
- String jobName;
+ final String jobName;
int startTime = 0;
int lateness = 0;
- int processingTime;
- int deadline;
+ final int processingTime;
+ final int deadline;
public Job(String jobName, int processingTime, int deadline) {
this.jobName = jobName;
diff --git a/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java b/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java
index 6e8611b86332..4fee4c4f0376 100644
--- a/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java
+++ b/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java
@@ -7,15 +7,15 @@
* @author shikarisohan
* @since 10/4/24
* Cohen-Sutherland Line Clipping Algorithm
- *
+ *
* This algorithm is used to clip a line segment to a rectangular window.
* It assigns a region code to each endpoint of the line segment, and
* then efficiently determines whether the line segment is fully inside,
* fully outside, or partially inside the window.
- *
- * Reference:
- * https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
- *
+ *
+ * Refere* https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
+ *
* Clipping window boundaries are defined as (xMin, yMin) and (xMax, yMax).
* The algorithm computes the clipped line segment if it's partially or
* fully inside the clipping window.
@@ -30,10 +30,10 @@ public class CohenSutherland {
private static final int TOP = 8; // 1000
// Define the clipping window
- double xMin;
- double yMin;
- double xMax;
- double yMax;
+ final double xMin;
+ final double yMin;
+ final double xMax;
+ final double yMax;
public CohenSutherland(double xMin, double yMin, double xMax, double yMax) {
this.xMin = xMin;
diff --git a/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java b/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
index 723e2bb2fbf9..67d9439de50b 100644
--- a/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
+++ b/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
@@ -14,8 +14,8 @@
* * if any, and returns the clipped line that lies inside the window.
* *
* * Reference:
- * * https://en.wikipedia.org/wiki/Liang%E2%80%93Barsky_algorithm
- *
+ * * ...
+ *
* Clipping window boundaries are defined as (xMin, yMin) and (xMax, yMax).
* The algorithm computes the clipped line segment if it's partially or
* fully inside the clipping window.
@@ -23,10 +23,10 @@
public class LiangBarsky {
// Define the clipping window
- double xMin;
- double xMax;
- double yMin;
- double yMax;
+ final double xMin;
+ final double xMax;
+ final double yMin;
+ final double yMax;
public LiangBarsky(double xMin, double yMin, double xMax, double yMax) {
this.xMin = xMin;
diff --git a/src/main/java/com/thealgorithms/maths/AbundantNumber.java b/src/main/java/com/thealgorithms/maths/AbundantNumber.java
index 804ac4d71477..b945885ffe07 100644
--- a/src/main/java/com/thealgorithms/maths/AbundantNumber.java
+++ b/src/main/java/com/thealgorithms/maths/AbundantNumber.java
@@ -4,10 +4,10 @@
* In number theory, an abundant number or excessive number is a positive integer for which
* the sum of its proper divisors is greater than the number.
* Equivalently, it is a number for which the sum of proper divisors (or aliquot sum) is greater than n.
- *
+ *
* The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16.
- *
- * Wiki: https://en.wikipedia.org/wiki/Abundant_number
+ *
+ Wiki: https://en.wikipedia.org/wiki/Abundant_number
*/
public final class AbundantNumber {
diff --git a/src/main/java/com/thealgorithms/maths/AliquotSum.java b/src/main/java/com/thealgorithms/maths/AliquotSum.java
index 996843b56826..98211df9ef79 100644
--- a/src/main/java/com/thealgorithms/maths/AliquotSum.java
+++ b/src/main/java/com/thealgorithms/maths/AliquotSum.java
@@ -7,7 +7,7 @@
* all proper divisors of n, that is, all divisors of n other than n itself. For
* example, the proper divisors of 15 (that is, the positive divisors of 15 that
* are not equal to 15) are 1, 3 and 5, so the aliquot sum of 15 is 9 i.e. (1 +
- * 3 + 5). Wikipedia: https://en.wikipedia.org/wiki/Aliquot_sum
+ * 3 + 5). Wikipedia: ...
*/
public final class AliquotSum {
private AliquotSum() {
diff --git a/src/main/java/com/thealgorithms/maths/AmicableNumber.java b/src/main/java/com/thealgorithms/maths/AmicableNumber.java
index b30831bfdc58..016870692828 100644
--- a/src/main/java/com/thealgorithms/maths/AmicableNumber.java
+++ b/src/main/java/com/thealgorithms/maths/AmicableNumber.java
@@ -13,7 +13,7 @@
* It is unknown if there are infinitely many pairs of amicable numbers.
*
*
- * link: https://en.wikipedia.org/wiki/Amicable_numbers
+ * link: ...
*
* Simple Example: (220, 284)
* 220 is divisible by {1,2,4,5,10,11,20,22,44,55,110} <-SUM = 284
@@ -27,7 +27,7 @@ private AmicableNumber() {
*
* @param from range start value
* @param to range end value (inclusive)
- * @return list with amicable numbers found in given range.
+ * @return set with amicable numbers found in given range.
*/
public static Set
* For example, 370 is an Armstrong number because 3^3 + 7^3 + 0^3 = 370.
* 1634 is an Armstrong number because 1^4 + 6^4 + 3^4 + 4^4 = 1634.
* An Armstrong number is often called a Narcissistic number.
diff --git a/src/main/java/com/thealgorithms/maths/ChebyshevIteration.java b/src/main/java/com/thealgorithms/maths/ChebyshevIteration.java
index bc30f1ba6e7e..005799957ee0 100644
--- a/src/main/java/com/thealgorithms/maths/ChebyshevIteration.java
+++ b/src/main/java/com/thealgorithms/maths/ChebyshevIteration.java
@@ -14,7 +14,7 @@
* m(A) (smallest eigenvalue) and M(A) (largest eigenvalue).
*
*
- * Wikipedia: https://en.wikipedia.org/wiki/Chebyshev_iteration
+ * Wikipedia: ...
*
* @author Mitrajit Ghorui(KeyKyrios)
*/
@@ -54,7 +54,7 @@ public static double[] solve(double[][] a, double[] b, double[] x0, double minEi
double d = (maxEigenvalue + minEigenvalue) / 2.0;
double c = (maxEigenvalue - minEigenvalue) / 2.0;
- double alpha = 0.0;
+ double alpha;
double alphaPrev = 0.0;
for (int k = 0; k < maxIterations; k++) {
diff --git a/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java b/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
index 87fc5af57b8d..9d15883ffc34 100644
--- a/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
+++ b/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
@@ -35,7 +35,7 @@ private static void padding(Collection
- * More info: https://en.wikipedia.org/wiki/Convolution_theorem
+ * More info: ...
*
* @param a The first signal.
* @param b The other signal.
diff --git a/src/main/java/com/thealgorithms/maths/Combinations.java b/src/main/java/com/thealgorithms/maths/Combinations.java
index 2b4a78613190..34fca3a20cef 100644
--- a/src/main/java/com/thealgorithms/maths/Combinations.java
+++ b/src/main/java/com/thealgorithms/maths/Combinations.java
@@ -40,8 +40,6 @@ public static long combinations(int n, int k) {
* Using this base value and above formula we can compute the next term
* nC(k+1)
*
- * @param n
- * @param k
* @return nCk
*/
public static long combinationsOptimized(int n, int k) {
diff --git a/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java b/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
index ed1ba1bbefc3..ac2fe09b1583 100644
--- a/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
+++ b/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
@@ -38,8 +38,8 @@ private static void padding(Collection
- * More info: https://en.wikipedia.org/wiki/Convolution_theorem
- * https://ccrma.stanford.edu/~jos/ReviewFourier/FFT_Convolution.html
+ * More info: ...
+ * ...
*
* @param a The first signal.
* @param b The other signal.
diff --git a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
index b652d4903da8..8d429c993f0f 100644
--- a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
+++ b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java
@@ -18,8 +18,8 @@ private DeterminantOfMatrix() {
static int determinant(int[][] a, int n) {
int det = 0;
int sign = 1;
- int p = 0;
- int q = 0;
+ int p;
+ int q;
if (n == 1) {
det = a[0][0];
} else {
diff --git a/src/main/java/com/thealgorithms/maths/DigitalRoot.java b/src/main/java/com/thealgorithms/maths/DigitalRoot.java
index e8f5305c7569..a7f5cc3269fa 100644
--- a/src/main/java/com/thealgorithms/maths/DigitalRoot.java
+++ b/src/main/java/com/thealgorithms/maths/DigitalRoot.java
@@ -4,13 +4,13 @@
* @author Suraj Kumar Modi
* You are given a number n. You need to find the digital root of n.
* DigitalRoot of a number is the recursive sum of its digits until we get a single digit number.
- *
+ *
* Test Case 1:
* Input:
* n = 1
* Output: 1
* Explanation: Digital root of 1 is 1
- *
+ *
* Test Case 2:
* Input:
* n = 99999
diff --git a/src/main/java/com/thealgorithms/maths/DistanceBetweenTwoPoints.java b/src/main/java/com/thealgorithms/maths/DistanceBetweenTwoPoints.java
index cd1c9205b328..acc34a633401 100644
--- a/src/main/java/com/thealgorithms/maths/DistanceBetweenTwoPoints.java
+++ b/src/main/java/com/thealgorithms/maths/DistanceBetweenTwoPoints.java
@@ -8,7 +8,7 @@
*
* Formula: d = sqrt((x2 - x1)^2 + (y2 - y1)^2)
*
- * Reference: https://en.wikipedia.org/wiki/Euclidean_distance
+ * Reference: ...
*/
public final class DistanceBetweenTwoPoints {
diff --git a/src/main/java/com/thealgorithms/maths/DistanceFormula.java b/src/main/java/com/thealgorithms/maths/DistanceFormula.java
index f7e2c7629551..28771ae149ac 100644
--- a/src/main/java/com/thealgorithms/maths/DistanceFormula.java
+++ b/src/main/java/com/thealgorithms/maths/DistanceFormula.java
@@ -29,7 +29,7 @@ public static int hammingDistance(int[] b1, int[] b2) {
}
public static double minkowskiDistance(double[] p1, double[] p2, int p) {
- double d = 0;
+ double d;
double distance = 0.0;
if (p1.length != p2.length) {
diff --git a/src/main/java/com/thealgorithms/maths/EulerMethod.java b/src/main/java/com/thealgorithms/maths/EulerMethod.java
index 3663b6c534aa..728af7291862 100644
--- a/src/main/java/com/thealgorithms/maths/EulerMethod.java
+++ b/src/main/java/com/thealgorithms/maths/EulerMethod.java
@@ -12,8 +12,8 @@
* is calculated by evaluating the differential equation at the previous step,
* multiplying the result with the step-size and adding it to the last y-value:
* y_n+1 = y_n + stepSize * f(x_n, y_n). (description adapted from
- * https://en.wikipedia.org/wiki/Euler_method ) (see also:
- * https://www.geeksforgeeks.org/euler-method-solving-differential-equation/ )
+ * ... ) (see also:
+ * ... )
*/
public final class EulerMethod {
private EulerMethod() {
diff --git a/src/main/java/com/thealgorithms/maths/EulerPseudoprime.java b/src/main/java/com/thealgorithms/maths/EulerPseudoprime.java
index 9a03f4e21d17..7341de13f48c 100644
--- a/src/main/java/com/thealgorithms/maths/EulerPseudoprime.java
+++ b/src/main/java/com/thealgorithms/maths/EulerPseudoprime.java
@@ -5,12 +5,12 @@
/**
* The {@code EulerPseudoprime} class implements the Euler primality test.
- *
+ *
* It is based on Euler’s criterion:
* For an odd prime number {@code n} and any integer {@code a} coprime to {@code n}:
* a^((n-1)/2) ≡ (a/n) (mod n)
* where (a/n) is the Jacobi symbol.
- *
+ *
* This algorithm is a stronger probabilistic test than Fermat’s test.
* It may still incorrectly identify a composite as “probably prime” (Euler pseudoprime),
* but such cases are rare.
diff --git a/src/main/java/com/thealgorithms/maths/EvilNumber.java b/src/main/java/com/thealgorithms/maths/EvilNumber.java
index 419133702fd4..2b6c80cf09e6 100644
--- a/src/main/java/com/thealgorithms/maths/EvilNumber.java
+++ b/src/main/java/com/thealgorithms/maths/EvilNumber.java
@@ -3,9 +3,9 @@
/**
* In number theory, an evil number is a non-negative integer that has an even number of 1s in its binary expansion.
* Non-negative integers that are not evil are called odious numbers.
- *
- * Evil Number Wiki: https://en.wikipedia.org/wiki/Evil_number
- * Odious Number Wiki: https://en.wikipedia.org/wiki/Odious_number
+ *
+ * Evil Number Wihttps://en.wikipedia.org/wiki/Evil_number
+ * Odious Number Wihttps://en.wikipedia.org/wiki/Odious_number
*/
public final class EvilNumber {
diff --git a/src/main/java/com/thealgorithms/maths/ExtendedEuclideanAlgorithm.java b/src/main/java/com/thealgorithms/maths/ExtendedEuclideanAlgorithm.java
index 4934d4493bf2..0649708df4e5 100644
--- a/src/main/java/com/thealgorithms/maths/ExtendedEuclideanAlgorithm.java
+++ b/src/main/java/com/thealgorithms/maths/ExtendedEuclideanAlgorithm.java
@@ -8,7 +8,7 @@
*
*
* For more details, see
- * https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
+ * ...
*/
public final class ExtendedEuclideanAlgorithm {
@@ -40,9 +40,8 @@ public static long[] extendedGCD(long a, long b) {
long y1 = result[2];
// Update coefficients using the results from the recursive call
- long x = y1;
long y = x1 - a / b * y1;
- return new long[] {gcd, x, y};
+ return new long[] {gcd, y1, y};
}
}
diff --git a/src/main/java/com/thealgorithms/maths/FFT.java b/src/main/java/com/thealgorithms/maths/FFT.java
index 91754bd1a80b..f0a3ff5f0522 100644
--- a/src/main/java/com/thealgorithms/maths/FFT.java
+++ b/src/main/java/com/thealgorithms/maths/FFT.java
@@ -21,7 +21,7 @@ private FFT() {
*
*
* More info:
- * https://introcs.cs.princeton.edu/java/32class/Complex.java.html
+ * ...
*/
static class Complex {
@@ -183,14 +183,13 @@ public double imaginary() {
*
*
* More info:
- * https://www.algorithm-archive.org/contents/cooley_tukey/cooley_tukey.html
- * https://www.geeksforgeeks.org/iterative-fast-fourier-transformation-polynomial-multiplication/
- * https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
- * https://cp-algorithms.com/algebra/fft.html
+ * ...
+ * ...
+ * ...
+ * ...
* @param x The discrete signal which is then converted to the FFT or the
* IFFT of signal x.
* @param inverse True if you want to find the inverse FFT.
- * @return
*/
public static ArrayList
* More info:
- * https://en.wikipedia.org/wiki/Chirp_Z-transform#Bluestein.27s_algorithm
- * http://tka4.org/materials/lib/Articles-Books/Numerical%20Algorithms/Hartley_Trasform/Bluestein%27s%20FFT%20algorithm%20-%20Wikipedia,%20the%20free%20encyclopedia.htm
+ * ...
+ * ...
*
* @param x The discrete signal which is then converted to the FFT or the
* IFFT of signal x.
diff --git a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
index 01a52b913d30..48dbff494f9e 100644
--- a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
+++ b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
@@ -12,7 +12,7 @@ private FastInverseSqrt() {
* Returns the inverse square root of the given number upto 6 - 8 decimal places.
* calculates the inverse square root of the given number and returns true if calculated answer
* matches with given answer else returns false
- *
+ *
* OUTPUT :
* Input - number = 4522
* Output: it calculates the inverse squareroot of a number and returns true with it matches the
diff --git a/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java b/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java
index 781275d3130d..a8c6cef46ad7 100644
--- a/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java
+++ b/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java
@@ -27,7 +27,7 @@ public static boolean isPerfectSquare(long number) {
* @param number the number
* @return true if {@code number} is a Fibonacci number, otherwise
* false
- * @link https://en.wikipedia.org/wiki/Fibonacci_number#Identification
+ * @link ...
*/
public static boolean isFibonacciNumber(long number) {
long value1 = 5 * number * number + 4;
diff --git a/src/main/java/com/thealgorithms/maths/GCD.java b/src/main/java/com/thealgorithms/maths/GCD.java
index df27516367b2..d92ad8a49b85 100644
--- a/src/main/java/com/thealgorithms/maths/GCD.java
+++ b/src/main/java/com/thealgorithms/maths/GCD.java
@@ -2,14 +2,14 @@
/**
* This class provides methods to compute the Greatest Common Divisor (GCD) of two or more integers.
- *
+ *
* The Greatest Common Divisor (GCD) of two or more integers is the largest positive integer that divides each of the integers without leaving a remainder.
- *
+ *
* The GCD can be computed using the Euclidean algorithm, which is based on the principle that the GCD of two numbers also divides their difference.
- *
+ *
* For more information, refer to the
* Greatest Common Divisor Wikipedia page.
- *
+ *
* Example usage:
*
* Reference:
- * https://technotip.com/6774/c-program-to-find-generic-root-of-a-number/
+ * ...
*/
public final class GenericRoot {
diff --git a/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java b/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
index 4e962722ba88..4d48d0750467 100644
--- a/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
+++ b/src/main/java/com/thealgorithms/maths/GoldbachConjecture.java
@@ -5,8 +5,8 @@
/**
* This is a representation of the unsolved problem of Goldbach's Projection, according to which every
* even natural number greater than 2 can be written as the sum of 2 prime numbers
- * More info: https://en.wikipedia.org/wiki/Goldbach%27s_conjecture
- * @author Vasilis Sarantidis (https://github.com/BILLSARAN)
+ * More info: ...
+ * @author Vasilis Sarantidis (...)
*/
public final class GoldbachConjecture {
diff --git a/src/main/java/com/thealgorithms/maths/HappyNumber.java b/src/main/java/com/thealgorithms/maths/HappyNumber.java
index bfe746953b33..835d08b91410 100644
--- a/src/main/java/com/thealgorithms/maths/HappyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/HappyNumber.java
@@ -38,7 +38,7 @@ public static boolean isHappy(int n) {
/**
* Calculates the sum of squares of the digits of a number.
- *
+ *
* Example:
* num = 82 → 8² + 2² = 64 + 4 = 68
*
diff --git a/src/main/java/com/thealgorithms/maths/KaprekarNumbers.java b/src/main/java/com/thealgorithms/maths/KaprekarNumbers.java
index 99842e2f4f5e..7206905becf7 100644
--- a/src/main/java/com/thealgorithms/maths/KaprekarNumbers.java
+++ b/src/main/java/com/thealgorithms/maths/KaprekarNumbers.java
@@ -25,7 +25,7 @@
*
* @see Kaprekar Number
* - Wikipedia
- * @author TheAlgorithms (https://github.com/TheAlgorithms)
+ * @author TheAlgorithms (...)
*/
public final class KaprekarNumbers {
private KaprekarNumbers() {
diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
index 9ec11e9b3220..5b9f94c1b7f2 100644
--- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
+++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
@@ -3,7 +3,7 @@
/**
* Is a common mathematics concept to find the smallest value number
* that can be divide using either number without having the remainder.
- * https://maticschool.blogspot.com/2013/11/find-least-common-multiple-lcm.html
+ * ...
* @author LauKinHoong
*/
public final class LeastCommonMultiple {
@@ -30,12 +30,14 @@ public static int lcm(int num1, int num2) {
num3 = num2;
}
- while (num1 != 0) {
- if (high % num1 == 0 && high % num2 == 0) {
- cmv = high;
- break;
+ if (num1 != 0) {
+ while (true) {
+ if (high % num1 == 0 && high % num2 == 0) {
+ cmv = high;
+ break;
+ }
+ high += num3;
}
- high += num3;
}
return cmv;
}
diff --git a/src/main/java/com/thealgorithms/maths/LongDivision.java b/src/main/java/com/thealgorithms/maths/LongDivision.java
index 45e97b1c14c3..6592a3682578 100644
--- a/src/main/java/com/thealgorithms/maths/LongDivision.java
+++ b/src/main/java/com/thealgorithms/maths/LongDivision.java
@@ -29,6 +29,23 @@ public static int divide(int dividend, int divisor) {
return 0;
}
+ StringBuilder answer = getStringBuilder(newDividend1, newDivisor1);
+
+ if ((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0)) {
+ try {
+ return Integer.parseInt(answer.toString()) * (-1);
+ } catch (NumberFormatException e) {
+ return -2147483648;
+ }
+ }
+ try {
+ return Integer.parseInt(answer.toString());
+ } catch (NumberFormatException e) {
+ return 2147483647;
+ }
+ }
+
+ private static StringBuilder getStringBuilder(long newDividend1, long newDivisor1) {
StringBuilder answer = new StringBuilder();
String dividendString = "" + newDividend1;
@@ -37,7 +54,7 @@ public static int divide(int dividend, int divisor) {
String remainder = "";
for (int i = 0; i < dividendString.length(); i++) {
- String partV1 = remainder + "" + dividendString.substring(lastIndex, i + 1);
+ String partV1 = remainder + dividendString.substring(lastIndex, i + 1);
long part1 = Long.parseLong(partV1);
if (part1 > newDivisor1) {
int quotient = 0;
@@ -55,7 +72,7 @@ public static int divide(int dividend, int divisor) {
answer.append(quotient);
} else if (part1 == 0) {
answer.append(0);
- } else if (part1 < newDivisor1) {
+ } else {
answer.append(0);
}
if (!(part1 == 0)) {
@@ -66,18 +83,6 @@ public static int divide(int dividend, int divisor) {
lastIndex++;
}
-
- if ((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0)) {
- try {
- return Integer.parseInt(answer.toString()) * (-1);
- } catch (NumberFormatException e) {
- return -2147483648;
- }
- }
- try {
- return Integer.parseInt(answer.toString());
- } catch (NumberFormatException e) {
- return 2147483647;
- }
+ return answer;
}
}
diff --git a/src/main/java/com/thealgorithms/maths/LuckyNumber.java b/src/main/java/com/thealgorithms/maths/LuckyNumber.java
index 70308e1e0edd..24e3b0c9b98f 100644
--- a/src/main/java/com/thealgorithms/maths/LuckyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/LuckyNumber.java
@@ -5,8 +5,8 @@
* This sieve is similar to the sieve of Eratosthenes that generates the primes,
* but it eliminates numbers based on their position in the remaining set,
* instead of their value (or position in the initial set of natural numbers).
- *
- * Wiki: https://en.wikipedia.org/wiki/Lucky_number
+ *
+ * Wihttps://en.wikipedia.org/wiki/Lucky_number
*/
public final class LuckyNumber {
diff --git a/src/main/java/com/thealgorithms/maths/MathBuilder.java b/src/main/java/com/thealgorithms/maths/MathBuilder.java
index 1cf3d8b7fc9a..5648c403a2f2 100644
--- a/src/main/java/com/thealgorithms/maths/MathBuilder.java
+++ b/src/main/java/com/thealgorithms/maths/MathBuilder.java
@@ -6,7 +6,7 @@
import java.util.function.Function;
/**
- * Author: Sadiul Hakim : https://github.com/sadiul-hakim
+ * Author: Sadiul Hakim : ...
* Profession: Backend Engineer
* Date: Oct 20, 2024
*/
diff --git a/src/main/java/com/thealgorithms/maths/Means.java b/src/main/java/com/thealgorithms/maths/Means.java
index cf6b88dd2d9f..2e90437675e6 100644
--- a/src/main/java/com/thealgorithms/maths/Means.java
+++ b/src/main/java/com/thealgorithms/maths/Means.java
@@ -1,8 +1,5 @@
package com.thealgorithms.maths;
-//import java.util.stream.StreamSupport;
-//import org.apache.commons.collections4.IterableUtils;
-
/**
* Utility class for computing various types of statistical means.
*
diff --git a/src/main/java/com/thealgorithms/maths/Neville.java b/src/main/java/com/thealgorithms/maths/Neville.java
index ca45f2e8a042..96af22cbbaf1 100644
--- a/src/main/java/com/thealgorithms/maths/Neville.java
+++ b/src/main/java/com/thealgorithms/maths/Neville.java
@@ -10,7 +10,7 @@
* computes the value of this polynomial at a given point.
*
*
- * Wikipedia: https://en.wikipedia.org/wiki/Neville%27s_algorithm
+ * Wikipedia: ...
*
* @author Mitrajit Ghorui(KeyKyrios)
*/
diff --git a/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java b/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java
index 9c95ebde3740..2c702f14f01b 100644
--- a/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java
+++ b/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java
@@ -4,7 +4,7 @@
* Find the 2 elements which are non-repeating in an array
* Reason to use bitwise operator: It makes our program faster as we are operating on bits and not
* on actual numbers.
- *
+ *
* Explanation of the code:
* Let us assume we have an array [1, 2, 1, 2, 3, 4]
* Property of XOR: num ^ num = 0.
diff --git a/src/main/java/com/thealgorithms/maths/PascalTriangle.java b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
index 9a9d4450cb98..5a8bffcf8480 100644
--- a/src/main/java/com/thealgorithms/maths/PascalTriangle.java
+++ b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
@@ -9,7 +9,7 @@ private PascalTriangle() {
*arises in probability theory, combinatorics, and algebra. In much of the Western world, it is
*named after the French mathematician Blaise Pascal, although other mathematicians studied it
*centuries before him in India, Persia, China, Germany, and Italy.
- *
+ *
* The rows of Pascal's triangle are conventionally enumerated starting with row n=0 at the top
*(the 0th row). The entries in each row are numbered from the left beginning with k=0 and are
*usually staggered relative to the numbers in the adjacent rows. The triangle may be
@@ -20,7 +20,7 @@ private PascalTriangle() {
*1 and 3 in the third row are added to produce the number 4 in the fourth row. *
*
*
- * link:-https://en.wikipedia.org/wiki/Pascal%27s_triangle
+ * li...ngle
*
*
* Example:-
diff --git a/src/main/java/com/thealgorithms/maths/PerfectCube.java b/src/main/java/com/thealgorithms/maths/PerfectCube.java
index 4104c6238580..1b6df9f2e93f 100644
--- a/src/main/java/com/thealgorithms/maths/PerfectCube.java
+++ b/src/main/java/com/thealgorithms/maths/PerfectCube.java
@@ -1,7 +1,7 @@
package com.thealgorithms.maths;
/**
- * https://en.wikipedia.org/wiki/Cube_(algebra)
+ * ...
*/
public final class PerfectCube {
private PerfectCube() {
diff --git a/src/main/java/com/thealgorithms/maths/PerfectNumber.java b/src/main/java/com/thealgorithms/maths/PerfectNumber.java
index f299d08e5d27..3b101a3db035 100644
--- a/src/main/java/com/thealgorithms/maths/PerfectNumber.java
+++ b/src/main/java/com/thealgorithms/maths/PerfectNumber.java
@@ -5,8 +5,8 @@
* sum of its positive divisors, excluding the number itself. For instance, 6
* has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a
* perfect number.
- *
- * link:https://en.wikipedia.org/wiki/Perfect_number
+ *
+ * l...mber
*/
public final class PerfectNumber {
private PerfectNumber() {
diff --git a/src/main/java/com/thealgorithms/maths/PerfectSquare.java b/src/main/java/com/thealgorithms/maths/PerfectSquare.java
index aec43062121a..9e7c314bb3be 100644
--- a/src/main/java/com/thealgorithms/maths/PerfectSquare.java
+++ b/src/main/java/com/thealgorithms/maths/PerfectSquare.java
@@ -1,7 +1,7 @@
package com.thealgorithms.maths;
/**
- * https://en.wikipedia.org/wiki/Perfect_square
+ * ...
*/
public final class PerfectSquare {
private PerfectSquare() {
diff --git a/src/main/java/com/thealgorithms/maths/PerrinNumber.java b/src/main/java/com/thealgorithms/maths/PerrinNumber.java
index cee45a1c5538..563a9ec592cc 100644
--- a/src/main/java/com/thealgorithms/maths/PerrinNumber.java
+++ b/src/main/java/com/thealgorithms/maths/PerrinNumber.java
@@ -5,7 +5,7 @@
* The Perrin Sequence is a sequence of integers defined by the recurrence relation:
* P(n) = P(n-2) + P(n-3) with initial values P(0) = 3, P(1) = 0, P(2) = 2.
* Example: 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, 22, 29, 39, 51...
- *
+ *
* Note: The Perrin Sequence uses the same recurrence relation as the Padovan Sequence
* but has different initial values.
*
diff --git a/src/main/java/com/thealgorithms/maths/PiApproximation.java b/src/main/java/com/thealgorithms/maths/PiApproximation.java
index 1be945d7ef24..4b4e5018c002 100644
--- a/src/main/java/com/thealgorithms/maths/PiApproximation.java
+++ b/src/main/java/com/thealgorithms/maths/PiApproximation.java
@@ -5,7 +5,7 @@
/**
* Implementation to calculate an estimate of the number π (Pi).
- *
+ *
* We take a random point P with coordinates (x, y) such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.
* If x² + y² ≤ 1, then the point is inside the quarter disk of radius 1,
* else the point is outside. We know that the probability of the point being
@@ -25,8 +25,8 @@ private PiApproximation() {
* where 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.
*/
static class Point {
- double x;
- double y;
+ final double x;
+ final double y;
Point(double x, double y) {
this.x = x;
diff --git a/src/main/java/com/thealgorithms/maths/PowerOfFour.java b/src/main/java/com/thealgorithms/maths/PowerOfFour.java
index e5fe6255821b..4d8b535b2f72 100644
--- a/src/main/java/com/thealgorithms/maths/PowerOfFour.java
+++ b/src/main/java/com/thealgorithms/maths/PowerOfFour.java
@@ -5,7 +5,7 @@
* A power of four is a number that can be expressed as 4^n where n is a non-negative integer.
* This class provides a method to determine if a given integer is a power of four using bit manipulation.
*
- * @author krishna-medapati (https://github.com/krishna-medapati)
+ * @author krishna-medapati (...)
*/
public final class PowerOfFour {
private PowerOfFour() {
@@ -13,12 +13,12 @@ private PowerOfFour() {
/**
* Checks if the given integer is a power of four.
- *
+ *
* A number is considered a power of four if:
* 1. It is greater than zero
* 2. It has exactly one '1' bit in its binary representation (power of two)
* 3. The '1' bit is at an even position (0, 2, 4, 6, ...)
- *
+ *
* The method uses the mask 0x55555555 (binary: 01010101010101010101010101010101)
* to check if the set bit is at an even position.
*
diff --git a/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java b/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
index 93c8252ab929..2618957311a7 100644
--- a/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
@@ -2,7 +2,7 @@
/**
* calculate Power using Recursion
- * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * @author Bama Charan Chhandogi (...)
*/
public final class PowerUsingRecursion {
diff --git a/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java b/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
index debe3a214a32..489ce82417e3 100644
--- a/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
+++ b/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java
@@ -9,8 +9,8 @@ private MillerRabinPrimalityCheck() {
/**
* Check whether the given number is prime or not
* MillerRabin algorithm is probabilistic. There is also an altered version which is deterministic.
- * https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
- * https://cp-algorithms.com/algebra/primality_tests.html
+ * ...
+ * ...
*
* @param n Whole number which is tested on primality
* @param k Number of iterations
diff --git a/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java b/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java
index 2780b113d904..6c49f90e5103 100644
--- a/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java
+++ b/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java
@@ -4,12 +4,12 @@
* Utility class to check if three integers form a Pythagorean triple.
* A Pythagorean triple consists of three positive integers a, b, and c,
* such that a² + b² = c².
- *
+ *
* Common examples:
* - (3, 4, 5)
* - (5, 12, 13)
- *
- * Reference: https://en.wikipedia.org/wiki/Pythagorean_triple
+ *
+ * Refhttps://en.wikipedia.org/wiki/Pythagorean_triple
*/
public final class PythagoreanTriple {
diff --git a/src/main/java/com/thealgorithms/maths/QuadraticEquationSolver.java b/src/main/java/com/thealgorithms/maths/QuadraticEquationSolver.java
index cd654c5dc023..126b812a173f 100644
--- a/src/main/java/com/thealgorithms/maths/QuadraticEquationSolver.java
+++ b/src/main/java/com/thealgorithms/maths/QuadraticEquationSolver.java
@@ -4,8 +4,8 @@
* This class represents a complex number which has real and imaginary part
*/
class ComplexNumber {
- Double real;
- Double imaginary;
+ final Double real;
+ final Double imaginary;
ComplexNumber(double real, double imaginary) {
this.real = real;
diff --git a/src/main/java/com/thealgorithms/maths/SecondMinMax.java b/src/main/java/com/thealgorithms/maths/SecondMinMax.java
index e5a2d3b89085..8ad4cb79f217 100644
--- a/src/main/java/com/thealgorithms/maths/SecondMinMax.java
+++ b/src/main/java/com/thealgorithms/maths/SecondMinMax.java
@@ -8,7 +8,7 @@ public final class SecondMinMax {
* Utility class for finding second maximum or minimum based on BiPredicate
* @exception IllegalArgumentException => if input array is of length less than 2 also if all elements are same
* @return the second minimum / maximum value from the input array
- * @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
+ * @author Bharath Sanjeevi ( ... )
*/
private SecondMinMax() {
@@ -35,7 +35,7 @@ private static int secondBest(final int[] arr, final int initialVal, final BiPre
* @param arr the input array
* @exception IllegalArgumentException => if input array is of length less than 2 also if all elements are same
* @return the second minimum / maximum value from the input array
- * @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
+ * @author Bharath Sanjeevi ( ... )
*/
public static int findSecondMin(final int[] arr) {
diff --git a/src/main/java/com/thealgorithms/maths/SieveOfAtkin.java b/src/main/java/com/thealgorithms/maths/SieveOfAtkin.java
index 780dd81dac7c..8e91e2b4a97b 100644
--- a/src/main/java/com/thealgorithms/maths/SieveOfAtkin.java
+++ b/src/main/java/com/thealgorithms/maths/SieveOfAtkin.java
@@ -6,7 +6,7 @@
/**
* Implementation of the Sieve of Atkin, an optimized algorithm to generate
* all prime numbers up to a given limit.
- *
+ *
* The Sieve of Atkin uses quadratic forms and modular arithmetic to identify
* prime candidates, then eliminates multiples of squares. It is more efficient
* than the Sieve of Eratosthenes for large limits.
@@ -54,7 +54,7 @@ public static List
* This method iterates over all x and y up to sqrt(limit) and applies
* the three quadratic forms used in the Sieve of Atkin. Numbers satisfying
* the modulo conditions are toggled in the sieve array.
@@ -104,7 +104,7 @@ private static void applyQuadraticForm(int n, int limit, boolean[] sieve, int mo
/**
* Toggles the sieve entry for a number if it satisfies the modulo condition and an additional boolean condition.
- *
+ *
* This version is used for the quadratic form 3*x*x - y*y, which requires x > y.
*
* @param n the number to check
@@ -121,7 +121,7 @@ private static void applyQuadraticForm(int n, int limit, boolean[] sieve, int mo
/**
* Eliminates numbers that are multiples of squares from the sieve.
- *
+ *
* All numbers that are multiples of i*i (where i is marked as prime) are
* marked non-prime to finalize the sieve. This ensures only actual primes remain.
*
diff --git a/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java b/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
index 5a15c4201a15..18f9d6140345 100644
--- a/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
+++ b/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
@@ -6,7 +6,7 @@
/**
* Sieve of Eratosthenes Algorithm
* An efficient algorithm to find all prime numbers up to a given limit.
- *
+ *
* Algorithm:
* 1. Create a boolean array of size n+1, initially all true
* 2. Mark 0 and 1 as not prime
@@ -14,7 +14,7 @@
* - If i is still marked as prime
* - Mark all multiples of i (starting from i²) as not prime
* 4. Collect all numbers still marked as prime
- *
+ *
* Time Complexity: O(n log log n)
* Space Complexity: O(n)
*
diff --git a/src/main/java/com/thealgorithms/maths/SmithNumber.java b/src/main/java/com/thealgorithms/maths/SmithNumber.java
index c06e0023d9bb..57057b5a8187 100644
--- a/src/main/java/com/thealgorithms/maths/SmithNumber.java
+++ b/src/main/java/com/thealgorithms/maths/SmithNumber.java
@@ -5,11 +5,11 @@
/**
* In number theory, a smith number is a composite number for which, in a given number base,
* the sum of its digits is equal to the sum of the digits in its prime factorization in the same base.
- *
+ *
* For example, in base 10, 378 = 21 X 33 X 71 is a Smith number since 3 + 7 + 8 = 2 X 1 + 3 X 3 + 7 X 1,
* and 22 = 21 X 111 is a Smith number, because 2 + 2 = 2 X 1 + (1 + 1) X 1.
- *
- * Wiki: https://en.wikipedia.org/wiki/Smith_number
+ *
+ Wiki: https://en.wikipedia.org/wiki/Smith_number
*/
public final class SmithNumber {
diff --git a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
index 0ea5643f1ca5..8a09603d0e33 100644
--- a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
+++ b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
@@ -1,4 +1,17 @@
package com.thealgorithms.maths;
-public class SquareRootWithNewtonRaphsonMethod {
-}
+ public final class SquareRootWithNewtonRaphsonMethod {
+ private SquareRootWithNewtonRaphsonMethod() {
+ }
+ public static double squareRoot(int n) {
+ double x = n; // initially taking a guess that x = n.
+ double root = 0.5 * (x + n / x); // applying Newton-Raphson Method.
+ while (Math.abs(root - x) > 0.0000001) { // root - x = error and error < 0.0000001, 0.0000001
+ // is the precision value taken over here.
+ x = root; // decreasing the value of x to root, i.e. decreasing the guess.
+ root = 0.5 * (x + n / x);
+ }
+ return root;
+ }
+ }
+
diff --git a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTest.java b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTest.java
index 80d185c93785..5e120acfffba 100644
--- a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTest.java
+++ b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonTest.java
@@ -14,8 +14,8 @@
* be changed according to the user preference.
*/
-public final class SquareRootWithNewtonRaphsonMethod {
- private SquareRootWithNewtonRaphsonMethod() {
+public final class SquareRootWithNewtonRaphsonTest {
+ private SquareRootWithNewtonRaphsonTest() {
}
public static double squareRoot(int n) {
diff --git a/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java b/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
index 315f0d3a7d28..c4899a23eba1 100644
--- a/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
+++ b/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
@@ -8,7 +8,7 @@
* difference of 2.
*
*
- * Wikipedia: https://en.wikipedia.org/wiki/Arithmetic_progression
+ * Wikipedia: ...
*/
public final class SumOfArithmeticSeries {
private SumOfArithmeticSeries() {
diff --git a/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java b/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
index c0a1e782659a..37b9a6429650 100644
--- a/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
+++ b/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
@@ -2,8 +2,8 @@
/**
* This program calculates the sum of the first n odd numbers.
- *
- * https://www.cuemath.com/algebra/sum-of-odd-numbers/
+ * * https://www.cuemath.com/algebra/sum-of-odd-numbers/
*/
public final class SumOfOddNumbers {
diff --git a/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java b/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
index 5369182a0a94..7597a8a727bc 100644
--- a/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
+++ b/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
@@ -5,7 +5,7 @@ public class SumWithoutArithmeticOperators {
/**
* Calculate the sum of two numbers a and b without using any arithmetic operators (+, -, *, /).
* All the integers associated are unsigned 32-bit integers
- *https://stackoverflow.com/questions/365522/what-is-the-best-way-to-add-two-numbers-without-using-the-operator
+ *...
*@param a - It is the first number
*@param b - It is the second number
*@return returns an integer which is the sum of the first and second number
diff --git a/src/main/java/com/thealgorithms/maths/TrinomialTriangle.java b/src/main/java/com/thealgorithms/maths/TrinomialTriangle.java
index 877ef4227afc..d708c2792d74 100644
--- a/src/main/java/com/thealgorithms/maths/TrinomialTriangle.java
+++ b/src/main/java/com/thealgorithms/maths/TrinomialTriangle.java
@@ -4,7 +4,7 @@
* The trinomial triangle is a variation of Pascal’s triangle. The difference
* between the two is that an entry in the trinomial triangle is the sum of the
* three (rather than the two in Pasacal’s triangle) entries above it
- *
+ *
* Example Input: n = 4 Output 1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 1
*/
public final class TrinomialTriangle {
diff --git a/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java b/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
index e2769744bcda..439108d815c6 100644
--- a/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
+++ b/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
@@ -18,21 +18,21 @@
* it's value expressed as a number. Let the direction ratios of the first
* vector, P be: a, b, c Let the direction ratios of the second vector, Q be: x,
* y, z Therefore the calculation for the cross product can be arranged as:
- *
+ *
* ``` P x Q: 1 1 1 a b c x y z ```
- *
+ *
* The direction ratios (DR) are calculated as follows: 1st DR, J: (b * z) - (c
* * y) 2nd DR, A: -((a * z) - (c * x)) 3rd DR, N: (a * y) - (b * x)
- *
+ *
* Therefore, the direction ratios of the cross product are: J, A, N The
* following Java Program calculates the direction ratios of the cross products
* of two vector. The program uses a function, cross() for doing so. The
* direction ratios for the first and the second vector has to be passed one by
* one separated by a space character.
- *
+ *
* Magnitude of a vector is the square root of the sum of the squares of the
* direction ratios.
- *
+ *
*
* For maintaining filename consistency, Vector class has been termed as
* VectorCrossProduct
diff --git a/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java b/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
index 13e795a91297..d3f3edf21af4 100644
--- a/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
@@ -3,7 +3,7 @@
/**
* This class provides methods to compute the inverse of a square matrix
* using Gaussian elimination. For more details, refer to:
- * https://en.wikipedia.org/wiki/Invertible_matrix
+ * ...
*/
public final class InverseOfMatrix {
private InverseOfMatrix() {
diff --git a/src/main/java/com/thealgorithms/matrix/LUDecomposition.java b/src/main/java/com/thealgorithms/matrix/LUDecomposition.java
index e41aaa201338..f42d51adc6c7 100644
--- a/src/main/java/com/thealgorithms/matrix/LUDecomposition.java
+++ b/src/main/java/com/thealgorithms/matrix/LUDecomposition.java
@@ -8,9 +8,9 @@
* where:
* - l is a lower triangular matrix with 1s on its diagonal
* - u is an upper triangular matrix
- *
- * Reference:
- * https://en.wikipedia.org/wiki/lu_decomposition
+ *
+ * Reference:* https://en.wikipedia.org/wiki/lu_decomposition
*/
public final class LUDecomposition {
@@ -21,8 +21,8 @@ private LUDecomposition() {
* A helper class to store both l and u matrices
*/
public static class LU {
- double[][] l;
- double[][] u;
+ final double[][] l;
+ final double[][] u;
LU(double[][] l, double[][] u) {
this.l = l;
diff --git a/src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java b/src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java
index 6467a438577b..627313ff3e5b 100644
--- a/src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java
+++ b/src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java
@@ -8,8 +8,8 @@
* matrix multiplication.
*
* For more details:
- * https://www.geeksforgeeks.org/java/java-program-to-multiply-two-matrices-of-any-size/
- * https://en.wikipedia.org/wiki/Matrix_multiplication
+ * ...
+ * ...
*
* Time Complexity: O(n^3) – where n is the dimension of the matrices
* (assuming square matrices for simplicity).
diff --git a/src/main/java/com/thealgorithms/matrix/MatrixRank.java b/src/main/java/com/thealgorithms/matrix/MatrixRank.java
index 6692b6c37c60..336b16cee264 100644
--- a/src/main/java/com/thealgorithms/matrix/MatrixRank.java
+++ b/src/main/java/com/thealgorithms/matrix/MatrixRank.java
@@ -52,7 +52,7 @@ public static int computeRank(double[][] matrix) {
}
private static boolean isZero(double value) {
- return Math.abs(value) < EPSILON;
+ return !(Math.abs(value) < EPSILON);
}
private static double[][] deepCopy(double[][] matrix) {
@@ -80,7 +80,7 @@ private static double[][] deepCopy(double[][] matrix) {
private static int findPivotRow(double[][] matrix, boolean[] rowMarked, int colIndex) {
int numRows = matrix.length;
for (int pivotRow = 0; pivotRow < numRows; ++pivotRow) {
- if (!rowMarked[pivotRow] && !isZero(matrix[pivotRow][colIndex])) {
+ if (!rowMarked[pivotRow] && isZero(matrix[pivotRow][colIndex])) {
return pivotRow;
}
}
@@ -115,7 +115,7 @@ private static void eliminateRows(double[][] matrix, int pivotRow, int colIndex)
int numRows = matrix.length;
int numColumns = matrix[0].length;
for (int otherRow = 0; otherRow < numRows; ++otherRow) {
- if (otherRow != pivotRow && !isZero(matrix[otherRow][colIndex])) {
+ if (otherRow != pivotRow && isZero(matrix[otherRow][colIndex])) {
for (int col2 = colIndex + 1; col2 < numColumns; ++col2) {
matrix[otherRow][col2] -= matrix[pivotRow][col2] * matrix[otherRow][colIndex];
}
diff --git a/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java b/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
index 1ec977af07c6..dea97d5aeb7d 100644
--- a/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
@@ -5,8 +5,8 @@
import java.util.List;
/**
- * Median of Matrix (https://medium.com/@vaibhav.yadav8101/median-in-a-row-wise-sorted-matrix-901737f3e116)
- * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ * Median of Matrix (...)
+ * Author: Bama Charan Chhandogi (...)
*/
public final class MedianOfMatrix {
diff --git a/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java b/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
index 4ae5970a9574..f729fef24e1d 100644
--- a/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
+++ b/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
@@ -12,7 +12,7 @@
* clockwise.
*
+ * See alhttps://en.wikipedia.org/wiki/MapReduce
*/
public final class MapReduce {
diff --git a/src/main/java/com/thealgorithms/misc/MedianOfRunningArray.java b/src/main/java/com/thealgorithms/misc/MedianOfRunningArray.java
index 95f86f63f720..95418f90bbcd 100644
--- a/src/main/java/com/thealgorithms/misc/MedianOfRunningArray.java
+++ b/src/main/java/com/thealgorithms/misc/MedianOfRunningArray.java
@@ -7,7 +7,7 @@
* A generic abstract class to compute the median of a dynamically growing stream of numbers.
*
* @param
* Usage:
* Extend this class and implement {@code calculateAverage(T a, T b)} to define how averaging is done.
*/
diff --git a/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java b/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
index c81476eaec32..691f305b5ee5 100644
--- a/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
@@ -6,9 +6,9 @@
* A simple way of knowing if a singly linked list is palindrome is to push all
* the values into a Stack and then compare the list to popped vales from the
* Stack.
- *
- * See more:
- * https://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/
+ *
+ * See more:* https://www.geeksforgeeks.org/function-to-check-if-a-singly-linked-list-is-palindrome/
*/
@SuppressWarnings("rawtypes")
public final class PalindromeSinglyLinkedList {
@@ -66,7 +66,7 @@ public static boolean isPalindromeOptimised(Node head) {
return true;
}
static class Node {
- int val;
+ final int val;
Node next;
Node(int val) {
this.val = val;
diff --git a/src/main/java/com/thealgorithms/misc/ShuffleArray.java b/src/main/java/com/thealgorithms/misc/ShuffleArray.java
index e07c8df771d3..76f9ee238eb6 100644
--- a/src/main/java/com/thealgorithms/misc/ShuffleArray.java
+++ b/src/main/java/com/thealgorithms/misc/ShuffleArray.java
@@ -11,10 +11,10 @@
* Best-case performance O(n)
* Average performance O(n)
* Worst-case space complexity O(1)
- *
+ *
* This class provides a static method to shuffle an array in place.
*
- * @author Rashi Dashore (https://github.com/rashi07dashore)
+ * @author Rashi Dasho(https://github.com/rashi07dashore)
*/
public final class ShuffleArray {
diff --git a/src/main/java/com/thealgorithms/misc/Sparsity.java b/src/main/java/com/thealgorithms/misc/Sparsity.java
index 4a919e0e55c6..a2f38f6598dd 100644
--- a/src/main/java/com/thealgorithms/misc/Sparsity.java
+++ b/src/main/java/com/thealgorithms/misc/Sparsity.java
@@ -4,10 +4,10 @@
* Utility class for calculating the sparsity of a matrix.
* A matrix is considered sparse if a large proportion of its elements are zero.
* Typically, if more than 2/3 of the elements are zero, the matrix is considered sparse.
- *
+ *
* Sparsity is defined as:
* sparsity = (number of zero elements) / (total number of elements)
- *
+ *
* This can lead to significant computational optimizations.
*/
public final class Sparsity {
diff --git a/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java b/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java
index 8ef10758ef80..4a78a3643666 100644
--- a/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java
+++ b/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java
@@ -35,8 +35,8 @@ public List
+ *
+ *
+ * @author Hardvan
+ */
+public final class ConvexHull {
+
+ private ConvexHull() {}
+
+ /**
+ * Computes the convex hull using the O(n³) brute-force method.
+ *
+ * @param points the input points
+ * @return the convex hull vertices
+ */
+ public static List
- *
- * > nm = new ArrayList<>();
+ static final List
> nm = new ArrayList<>();
// adjacency list
private ArrayList
* int decimal = BcdConversion.bcdToDecimal(0x1234);
diff --git a/src/main/java/com/thealgorithms/bitmanipulation/ClearLeftmostSetBit.java b/src/main/java/com/thealgorithms/bitmanipulation/ClearLeftmostSetBit.java
index 3e9a4a21183f..9ecf1eda1e6d 100644
--- a/src/main/java/com/thealgorithms/bitmanipulation/ClearLeftmostSetBit.java
+++ b/src/main/java/com/thealgorithms/bitmanipulation/ClearLeftmostSetBit.java
@@ -3,7 +3,7 @@
/**
* ClearLeftmostSetBit class contains a method to clear the leftmost set bit of a number.
* The leftmost set bit is the leftmost bit that is set to 1 in the binary representation of a number.
- *
+ *
* int binary = Xs3Conversion.xs3ToBinary(0x4567);
diff --git a/src/main/java/com/thealgorithms/ciphers/AffineCipher.java b/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
index 979f18532eaa..c12907088ee2 100644
--- a/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
@@ -3,10 +3,10 @@
/**
* The AffineCipher class implements the Affine cipher, a type of monoalphabetic substitution cipher.
* It encrypts and decrypts messages using a linear transformation defined by the formula:
- *
+ *
* RSA rsa = new RSA(1024);
diff --git a/src/main/java/com/thealgorithms/ciphers/RailFenceCipher.java b/src/main/java/com/thealgorithms/ciphers/RailFenceCipher.java
index f81252980468..596c414b79b4 100644
--- a/src/main/java/com/thealgorithms/ciphers/RailFenceCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/RailFenceCipher.java
@@ -5,8 +5,8 @@
/**
* The rail fence cipher (also called a zigzag cipher) is a classical type of transposition cipher.
* It derives its name from the manner in which encryption is performed, in analogy to a fence built with horizontal rails.
- * https://en.wikipedia.org/wiki/Rail_fence_cipher
- * @author https://github.com/Krounosity
+ * ...
+ * @author ...
*/
public class RailFenceCipher {
diff --git a/src/main/java/com/thealgorithms/ciphers/SimpleSubCipher.java b/src/main/java/com/thealgorithms/ciphers/SimpleSubCipher.java
index f6c88ef730ec..b4edcf20ac50 100644
--- a/src/main/java/com/thealgorithms/ciphers/SimpleSubCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/SimpleSubCipher.java
@@ -15,8 +15,6 @@ public class SimpleSubCipher {
/**
* Encrypt text by replacing each element with its opposite character.
*
- * @param message
- * @param cipherSmall
* @return Encrypted message
*/
public String encode(String message, String cipherSmall) {
@@ -52,8 +50,6 @@ public String encode(String message, String cipherSmall) {
* Decrypt message by replacing each element with its opposite character in
* cipher.
*
- * @param encryptedMessage
- * @param cipherSmall
* @return message
*/
public String decode(String encryptedMessage, String cipherSmall) {
diff --git a/src/main/java/com/thealgorithms/ciphers/Vigenere.java b/src/main/java/com/thealgorithms/ciphers/Vigenere.java
index 0f117853bb85..ad5ee18a3cd5 100644
--- a/src/main/java/com/thealgorithms/ciphers/Vigenere.java
+++ b/src/main/java/com/thealgorithms/ciphers/Vigenere.java
@@ -2,24 +2,24 @@
/**
* A Java implementation of the Vigenère Cipher.
- *
+ *
* List
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java b/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
index dac88dd9f241..1d3a2c056f24 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
@@ -35,7 +35,7 @@ public class RandomNode {
static class ListNode {
- int val;
+ final int val;
ListNode next;
ListNode(int val) {
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java b/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
index 9b9464d388b5..51043229107a 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java
@@ -28,7 +28,7 @@
*
* {
- S val;
+ final S val;
DequeNode next = null;
DequeNode prev = null;
@@ -59,12 +59,11 @@ public void addLast(T val) {
DequeNode> traverse(BinaryTree.Node root) {
// traverse all the level nodes
for (int i = 0; i < nodesOnLevel; i++) {
BinaryTree.Node node = q.poll();
+ assert node != null;
if (prevLevelFromLeftToRight) {
- level.add(0, node.data);
+ level.addFirst(node.data);
} else {
level.add(node.data);
}
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java b/src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java
index 6c53666e5856..f5559f990166 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java
@@ -53,7 +53,7 @@ class NRKTree {
public NRKTree left;
public NRKTree right;
- public int data;
+ public final int data;
NRKTree(int x) {
this.left = null;
diff --git a/src/main/java/com/thealgorithms/devutils/nodes/Node.java b/src/main/java/com/thealgorithms/devutils/nodes/Node.java
index a10817830962..d239db7d8b86 100644
--- a/src/main/java/com/thealgorithms/devutils/nodes/Node.java
+++ b/src/main/java/com/thealgorithms/devutils/nodes/Node.java
@@ -3,7 +3,7 @@
/**
* Base class for any node implementation which contains a generic type
* variable.
- *
+ *
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Abbreviation.java b/src/main/java/com/thealgorithms/dynamicprogramming/Abbreviation.java
index 60c0fd0a3cde..b4278e203d7f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/Abbreviation.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/Abbreviation.java
@@ -2,12 +2,12 @@
/**
* A class that provides a solution to the abbreviation problem.
- *
+ * > adjacencyList, List
- *
*/
public final class ZeroOneBfs {
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java b/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java
index 54ba4eb650a8..6741d978b2f6 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java
@@ -14,7 +14,7 @@ private ActivitySelection() {
/**
* Function to perform activity selection using a greedy approach.
- *
+ *
* int result1 = GCD.gcd(48, 18);
diff --git a/src/main/java/com/thealgorithms/maths/GCDRecursion.java b/src/main/java/com/thealgorithms/maths/GCDRecursion.java
index e95ce97c8a04..6c251654f27b 100644
--- a/src/main/java/com/thealgorithms/maths/GCDRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/GCDRecursion.java
@@ -1,7 +1,7 @@
package com.thealgorithms.maths;
/**
- * @author https://github.com/shellhub/
+ * @author ...
*/
public final class GCDRecursion {
private GCDRecursion() {
diff --git a/src/main/java/com/thealgorithms/maths/Gaussian.java b/src/main/java/com/thealgorithms/maths/Gaussian.java
index 1e02579757cc..b3095437cd1f 100644
--- a/src/main/java/com/thealgorithms/maths/Gaussian.java
+++ b/src/main/java/com/thealgorithms/maths/Gaussian.java
@@ -9,7 +9,7 @@ private Gaussian() {
public static ArrayList
> bruteForce(int[] nums, int target) {
public List
> twoPointer(int[] nums, int target) {
Arrays.sort(nums);
List
> arr = new ArrayList