> taskPerformed, int total) {
/**
* Counts the ways to assign tasks until the given task number with the specified mask.
*
- * @param mask the bitmask representing the current state of assignments.
- * @param taskNo the current task number being processed.
+ * @param mask the bitmask representing the current state of assignments.
+ * @param taskNo the current task number being processed.
* @return the number of ways to assign tasks.
*/
private int countWaysUntil(int mask, int taskNo) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
index 8494492f293f..05f235b17e36 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
@@ -2,6 +2,7 @@
/**
* Java program for Boundary fill algorithm.
+ *
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
*/
public final class BoundaryFill {
@@ -11,7 +12,7 @@ private BoundaryFill() {
/**
* Get the color at the given co-odrinates of a 2D image
*
- * @param image The image to be filled
+ * @param image The image to be filled
* @param xCoordinate The x co-ordinate of which color is to be obtained
* @param yCoordinate The y co-ordinate of which color is to be obtained
*/
@@ -22,7 +23,7 @@ public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
/**
* Put the color at the given co-odrinates of a 2D image
*
- * @param image The image to be filed
+ * @param image The image to be filed
* @param xCoordinate The x co-ordinate at which color is to be filled
* @param yCoordinate The y co-ordinate at which color is to be filled
*/
@@ -33,10 +34,10 @@ public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int
/**
* Fill the 2D image with new color
*
- * @param image The image to be filed
- * @param xCoordinate The x co-ordinate at which color is to be filled
- * @param yCoordinate The y co-ordinate at which color is to be filled
- * @param newColor The new color which to be filled in the image
+ * @param image The image to be filed
+ * @param xCoordinate The x co-ordinate at which color is to be filled
+ * @param yCoordinate The y co-ordinate at which color is to be filled
+ * @param newColor The new color which to be filled in the image
* @param boundaryColor The old color which is to be replaced in the image
*/
public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java b/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
index 3c1851a8c46c..625022b9482c 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
@@ -30,7 +30,7 @@ private BruteForceKnapsack() {
* @param wt an array where wt[i] represents the weight of the i-th item
* @param val an array where val[i] represents the value of the i-th item
* @param n the number of items available for selection
- * @return the maximum value that can be obtained with the given capacity
+ * @return the maximum value that can be obtained with the given capacity
*
* The function uses recursion to explore all possible subsets of items.
* For each item, it has two choices: either include it in the knapsack
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
index d01066f611bd..e77606c51ae3 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
@@ -1,10 +1,11 @@
package com.thealgorithms.dynamicprogramming;
import java.util.Scanner;
+
/**
* 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
@@ -17,9 +18,8 @@ private CatalanNumber() {
* This method finds the nth Catalan number
*
* @param n input n which determines the nth Catalan number n should be less
- * than equal to 50 as 50th Catalan number is 6,533,841,209,031,609,592 for
- * n > 50, BigInteger class should be used instead long
- *
+ * than equal to 50 as 50th Catalan number is 6,533,841,209,031,609,592 for
+ * n > 50, BigInteger class should be used instead long
* @return catalanArray[n] the nth Catalan number
*/
static long findNthCatalan(int n) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/ClimbingStairs.java b/src/main/java/com/thealgorithms/dynamicprogramming/ClimbingStairs.java
index 0f0f5375ba82..653f06e09d01 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/ClimbingStairs.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/ClimbingStairs.java
@@ -27,9 +27,9 @@ private ClimbingStairs() {
*
* @param n the no. of steps in the staircase (non-negative integer)
* @return the no. of distinct ways to climb to the top
- * - Returns 0 if n is 0 (no steps to climb).
- * - Returns 1 if n is 1 (only one way to climb).
- * - For n > 1, it returns the total no. of ways to climb.
+ * - Returns 0 if n is 0 (no steps to climb).
+ * - Returns 1 if n is 1 (only one way to climb).
+ * - For n > 1, it returns the total no. of ways to climb.
*/
public static int numberOfWays(int n) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java b/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
index 7edc9603dc8b..caf7093c4c63 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CoinChange.java
@@ -11,9 +11,9 @@ private CoinChange() {
* This method finds the number of combinations of getting change for a
* given amount and change coins
*
- * @param coins The list of coins
+ * @param coins The list of coins
* @param amount The amount for which we need to find the change Finds the
- * number of combinations of change
+ * number of combinations of change
*/
public static int change(int[] coins, int amount) {
int[] combinations = new int[amount + 1];
@@ -31,9 +31,9 @@ public static int change(int[] coins, int amount) {
/**
* This method finds the minimum number of coins needed for a given amount.
*
- * @param coins The list of coins
+ * @param coins The list of coins
* @param amount The amount for which we need to find the minimum number of
- * coins. Finds the minimum number of coins that make a given value.
+ * coins. Finds the minimum number of coins that make a given value.
*/
public static int minimumCoins(int[] coins, int amount) {
// minimumCoins[i] will store the minimum coins needed for amount i
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java b/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
index e731524d4958..299f9ec97eaa 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
@@ -2,10 +2,10 @@
/**
* @author Siddhant Swarup Mallick
-
+ *
* In mathematics, the Golomb sequence is a non-decreasing integer sequence where n-th term is equal
* to number of times n appears in the sequence.
-
+ *
* Wikipedia
* Program description - To find the Golomb sequence upto n
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
index 0d6aff2bbef3..4c4a52e5f79f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java
@@ -16,7 +16,7 @@ private Fibonacci() {
* This method finds the nth fibonacci number using memoization technique
*
* @param n The input n for which we have to determine the fibonacci number
- * Outputs the nth fibonacci number
+ * Outputs the nth fibonacci number
* @throws IllegalArgumentException if n is negative
*/
public static int fibMemo(int n) {
@@ -42,7 +42,7 @@ public static int fibMemo(int n) {
* This method finds the nth fibonacci number using bottom up
*
* @param n The input n for which we have to determine the fibonacci number
- * Outputs the nth fibonacci number
+ * Outputs the nth fibonacci number
* @throws IllegalArgumentException if n is negative
*/
public static int fibBotUp(int n) {
@@ -68,13 +68,13 @@ public static int fibBotUp(int n) {
* This method finds the nth fibonacci number using bottom up
*
* @param n The input n for which we have to determine the fibonacci number
- * Outputs the nth fibonacci number
- *
- * This is optimized version of Fibonacci Program. Without using Hashmap and
- * recursion. It saves both memory and time. Space Complexity will be O(1)
- * Time Complexity will be O(n)
- *
- * Whereas , the above functions will take O(n) Space.
+ * Outputs the nth fibonacci number
+ *
+ * This is optimized version of Fibonacci Program. Without using Hashmap and
+ * recursion. It saves both memory and time. Space Complexity will be O(1)
+ * Time Complexity will be O(n)
+ *
+ * Whereas , the above functions will take O(n) Space.
* @throws IllegalArgumentException if n is negative
* @author Shoaib Rayeen (https://github.com/shoaibrayeen)
*/
@@ -104,8 +104,9 @@ public static int fibOptimized(int n) {
* = 1.6180339887... Now, let's look at Binet's formula: Sn = Φⁿ–(– Φ⁻ⁿ)/√5 We first calculate
* the squareRootof5 and phi and store them in variables. Later, we apply Binet's formula to get
* the required term. Time Complexity will be O(1)
+ *
* @param n The input n for which we have to determine the fibonacci number
- * Outputs the nth fibonacci number
+ * Outputs the nth fibonacci number
* @throws IllegalArgumentException if n is negative
*/
public static int fibBinet(int n) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
index 7a0a3da94c1e..ec1e828a9c4c 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 {
@@ -15,12 +15,12 @@ private KadaneAlgorithm() {
* Computes the maximum subarray sum using Kadane's Algorithm and checks
* if it matches a predicted answer.
*
- * @param a The input array of integers for which the maximum
- * subarray sum is to be calculated.
+ * @param a The input array of integers for which the maximum
+ * subarray sum is to be calculated.
* @param predictedAnswer The expected maximum subarray sum to be verified
- * against the computed sum.
+ * against the computed sum.
* @return true if the computed maximum subarray sum equals the predicted
- * answer, false otherwise.
+ * answer, false otherwise.
*
*
Example:
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java
index 119d65dfe365..2a290c5c3b2f 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,20 +43,20 @@ 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.
*/
public static int optimizedLevenshteinDistance(final String string1, final String string2) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java
index 08039b85ce40..2be2a7235960 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java
@@ -23,7 +23,7 @@ private LongestAlternatingSubsequence() {
* Finds the length of the longest alternating subsequence in the given array.
*
* @param arr an array of integers where the longest alternating subsequence is to be found
- * @param n the length of the array {@code arr}
+ * @param n the length of the array {@code arr}
* @return the length of the longest alternating subsequence
*
*
The method uses dynamic programming to solve the problem. It maintains a 2D array
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
index b5ac62b4674b..01a1ce31c3b9 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java
@@ -8,7 +8,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..df8ae43f5ad1 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 {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java
index 8a4ab2f526a9..4b63f3e4d9b5 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java
@@ -5,7 +5,6 @@
*
* A palindromic substring is a sequence of characters that reads the same backward as forward.
* This class uses a dynamic programming approach to efficiently find the longest palindromic substring.
- *
*/
public final class LongestPalindromicSubstring {
private LongestPalindromicSubstring() {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java b/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java
index 1edb7207dee2..500129e52761 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java
@@ -24,7 +24,7 @@ private MatrixChainMultiplication() {
* @param matrices an ArrayList of Matrix objects representing the matrices
* to be multiplied.
* @return a Result object containing the matrices of minimum costs and
- * optimal splits.
+ * optimal splits.
*/
public static Result calculateMatrixChainOrder(ArrayList matrices) {
int size = matrices.size();
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java b/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java
index 0c1031c6805c..6da82cf4fac9 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java
@@ -24,7 +24,7 @@ private MatrixChainRecursiveTopDownMemoisation() {
* @param p an array of integers representing the dimensions of the matrices.
* The length of the array is n + 1, where n is the number of matrices.
* @return the minimum number of multiplications required to multiply the chain
- * of matrices.
+ * of matrices.
*/
static int memoizedMatrixChain(int[] p) {
int n = p.length;
@@ -46,7 +46,7 @@ static int memoizedMatrixChain(int[] p) {
* @param i the starting index of the matrix chain.
* @param j the ending index of the matrix chain.
* @return the minimum number of multiplications needed to multiply matrices
- * from i to j.
+ * from i to j.
*/
static int lookupChain(int[][] m, int[] p, int i, int j) {
if (i == j) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java b/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
index 49af3ae3db88..11595357d57f 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/MaximumSumOfNonAdjacentElements.java
@@ -15,6 +15,7 @@ private MaximumSumOfNonAdjacentElements() {
* Approach 1: Uses a dynamic programming array to store the maximum sum at
* each index. Time Complexity: O(n) - where n is the length of the input
* array. Space Complexity: O(n) - due to the additional dp array.
+ *
* @param arr The input array of integers.
* @return The maximum sum of non-adjacent elements.
*/
@@ -54,6 +55,7 @@ public static int getMaxSumApproach1(int[] arr) {
* of an array. Time Complexity: O(n) - where n is the length of the input
* array. Space Complexity: O(1) - as it only uses constant space for two
* variables.
+ *
* @param arr The input array of integers.
* @return The maximum sum of non-adjacent elements.
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
index 3db40148f1c2..9ce798a3687c 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
@@ -29,10 +29,10 @@ private NewManShanksPrime() {
* Calculates the nth New Man Shanks prime and checks if it equals the
* expected answer.
*
- * @param n the index of the New Man Shanks prime to calculate (0-based).
+ * @param n the index of the New Man Shanks prime to calculate (0-based).
* @param expectedAnswer the expected value of the nth New Man Shanks prime.
* @return true if the calculated nth New Man Shanks prime matches the
- * expected answer; false otherwise.
+ * expected answer; false otherwise.
*/
public static boolean nthManShanksPrime(int n, int expectedAnswer) {
int[] a = new int[n + 1];
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
index e31bb73096e8..92e9acb88ff7 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/OptimalJobScheduling.java
@@ -2,9 +2,9 @@
/**
* This class refers to the Optimal Job Scheduling problem with the following constrains:
- * - precedence relation between the processes
- * - machine pair dependent transportation delays
- *
+ * - precedence relation between the processes
+ * - machine pair dependent transportation delays
+ *
* https://en.wikipedia.org/wiki/Optimal_job_scheduling
*
* @author georgioct@csd.auth.gr
@@ -19,11 +19,12 @@ public class OptimalJobScheduling {
/**
* Constructor of the class.
+ *
* @param numberProcesses ,refers to the number of precedent processes(N)
- * @param numberMachines ,refers to the number of different machines in our disposal(M)
- * @param run , N*M matrix refers to the cost of running each process to each machine
- * @param transfer ,M*M symmetric matrix refers to the transportation delay for each pair of
- * machines
+ * @param numberMachines ,refers to the number of different machines in our disposal(M)
+ * @param run , N*M matrix refers to the cost of running each process to each machine
+ * @param transfer ,M*M symmetric matrix refers to the transportation delay for each pair of
+ * machines
*/
public OptimalJobScheduling(int numberProcesses, int numberMachines, int[][] run, int[][] transfer) {
this.numberProcesses = numberProcesses;
@@ -88,8 +89,9 @@ private int runningCost(int process, int machine) {
/**
* Function used in order to return the minimum Cost.
+ *
* @param costArr ,an Array of size M which refers to the costs of executing a Process to each
- * Machine
+ * Machine
* @return the minimum cost
*/
private int findMin(int[] costArr) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java b/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
index 49c4a0a3a008..36b2b0ecb07b 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/PartitionProblem.java
@@ -1,16 +1,16 @@
/**
* @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.
* nums1 = {1, 2}
* nums2 = {3}
- *
+ *
* The time complexity of the solution is O(n × sum) and requires O(n × sum) space
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
index 181ac72a654d..bf2de689d337 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
@@ -5,9 +5,9 @@
* 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
*/
@@ -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.
*
@@ -64,12 +64,12 @@ 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.
*
- * @param src The source string to be matched against the pattern.
- * @param pat The pattern containing wildcards ('*' matches a sequence of characters, '?' matches a single character).
+ * @param src The source string to be matched against the pattern.
+ * @param pat The pattern containing wildcards ('*' matches a sequence of characters, '?' matches a single character).
* @param svidx The current index in the source string.
* @param pvidx The current index in the pattern.
* @return {@code true} if the source string matches the pattern, {@code false} otherwise.
@@ -108,15 +108,15 @@ 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.
*
- * @param src The source string to be matched against the pattern.
- * @param pat The pattern containing wildcards ('*' matches a sequence of characters, '?' matches a single character).
+ * @param src The source string to be matched against the pattern.
+ * @param pat The pattern containing wildcards ('*' matches a sequence of characters, '?' matches a single character).
* @param svidx The current index in the source string.
* @param pvidx The current index in the pattern.
- * @param strg A 2D array used for memoization to store the results of subproblems.
+ * @param strg A 2D array used for memoization to store the results of subproblems.
* @return {@code true} if the source string matches the pattern, {@code false} otherwise.
*/
public static boolean regexRecursion(String src, String pat, int svidx, int pvidx, int[][] strg) {
@@ -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/RodCutting.java b/src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java
index 6d33826b6b17..d095055efff5 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java
@@ -15,8 +15,8 @@ private RodCutting() {
* @param price An array representing the prices of different pieces, where price[i-1]
* represents the price of a piece of length i.
* @param n The length of the rod to be cut.
- * @throws IllegalArgumentException if the price array is null or empty, or if n is less than 0.
* @return The maximum obtainable value.
+ * @throws IllegalArgumentException if the price array is null or empty, or if n is less than 0.
*/
public static int cutRod(int[] price, int n) {
if (price == null || price.length == 0) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
index 0c5bc2c5884d..474d797c9427 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
@@ -4,6 +4,7 @@
* Find the number of subsets present in the given array with a sum equal to target.
* Based on Solution discussed on
* StackOverflow
+ *
* @author Samrat Podder
*/
public final class SubsetCount {
@@ -14,9 +15,9 @@ private SubsetCount() {
* Dynamic Programming Implementation.
* Method to find out the number of subsets present in the given array with a sum equal to
* target. Time Complexity is O(n*target) and Space Complexity is O(n*target)
- * @param arr is the input array on which subsets are to searched
- * @param target is the sum of each element of the subset taken together
*
+ * @param arr is the input array on which subsets are to searched
+ * @param target is the sum of each element of the subset taken together
*/
public static int getCount(int[] arr, int target) {
/*
@@ -49,7 +50,8 @@ public static int getCount(int[] arr, int target) {
* This Method is a Space Optimized version of the getCount(int[], int) method and solves the
* same problem This approach is a bit better in terms of Space Used Time Complexity is
* O(n*target) and Space Complexity is O(target)
- * @param arr is the input array on which subsets are to searched
+ *
+ * @param arr is the input array on which subsets are to searched
* @param target is the sum of each element of the subset taken together
*/
public static int getCountSO(int[] arr, int target) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java
index da8667afd0ce..c3a11734db92 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java
@@ -10,7 +10,7 @@ private SubsetSum() {
* @param arr the array containing integers.
* @param sum the target sum of the subset.
* @return {@code true} if a subset exists that sums to the given value,
- * otherwise {@code false}.
+ * otherwise {@code false}.
*/
public static boolean subsetSum(int[] arr, int sum) {
int n = arr.length;
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSumSpaceOptimized.java b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSumSpaceOptimized.java
index 946da46cb292..44b811706323 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSumSpaceOptimized.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetSumSpaceOptimized.java
@@ -1,4 +1,5 @@
package com.thealgorithms.dynamicprogramming;
+
/*
The Sum of Subset problem determines whether a subset of elements from a
given array sums up to a specific target value.
@@ -6,6 +7,7 @@
public final class SubsetSumSpaceOptimized {
private SubsetSumSpaceOptimized() {
}
+
/**
* This method checks whether the subset of an array
* contains a given sum or not. This is an space
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
index e9c15c1b4f24..95890b9ed63d 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
@@ -3,10 +3,10 @@
/**
* 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
*/
public final class SumOfSubset {
@@ -22,13 +22,13 @@ 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
- * remaining elements can sum up to the remaining target.
- * 2. Exclude the current element and check if the remaining elements
- * can sum up to the target without this element.
+ *
+ * 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
+ * remaining elements can sum up to the remaining target.
+ * 2. Exclude the current element and check if the remaining elements
+ * can sum up to the target without this element.
*/
public static boolean subsetSum(int[] arr, int num, int key) {
if (key == 0) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java b/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
index 8c7ea6179e3f..5cec8f1e7c1b 100755
--- a/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java
@@ -53,11 +53,11 @@ public static int countSubseq(String str) {
*
Uses a HashSet to avoid counting duplicate characters within
* a single subsequence.
*
- * @param st the input string
+ * @param st the input string
* @param idx the current index from which to calculate subsequences
- * @param dp dynamic programming array used to memoize results
+ * @param dp dynamic programming array used to memoize results
* @return the total number of unique subsequences starting from the
- * current index
+ * current index
*/
public static int countSubsequences(String st, int idx, int[] dp) {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/WildcardMatching.java b/src/main/java/com/thealgorithms/dynamicprogramming/WildcardMatching.java
index 8e8bf3cc6606..b51da191c23b 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/WildcardMatching.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/WildcardMatching.java
@@ -1,15 +1,13 @@
/**
- *
* Author: Janmesh Singh
* Github: https://github.com/janmeshjs
-
+ *
* Problem Statement: To determine if the pattern matches the text.
* The pattern can include two special wildcard characters:
- * ' ? ': Matches any single character.
- * ' * ': Matches zero or more of any character sequence.
- *
+ * ' ? ': Matches any single character.
+ * ' * ': Matches zero or more of any character sequence.
+ *
* Use DP to return True if the pattern matches the entire text and False otherwise
- *
*/
package com.thealgorithms.dynamicprogramming;
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java b/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
index 022b43184a88..bd753841de42 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/WineProblem.java
@@ -5,23 +5,23 @@
* 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.
- *
+ * - 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.
- *
+ * 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)
- * - Space Complexity: O(N^2) for the table.
+ * compute the maximum profit for all possible subproblems.
+ * - Time Complexity: O(N^2)
+ * - Space Complexity: O(N^2) for the table.
*/
public final class WineProblem {
private WineProblem() {
@@ -80,8 +80,8 @@ public static int wptd(int[] arr, int si, int ei, int[][] strg) {
* Calculate maximum profit using bottom-up dynamic programming with tabulation.
*
* @param arr Array of wine prices.
- * @throws IllegalArgumentException if the input array is null or empty.
* @return Maximum profit obtainable by selling the wines.
+ * @throws IllegalArgumentException if the input array is null or empty.
*/
public static int wpbu(int[] arr) {
if (arr == null || arr.length == 0) {
diff --git a/src/main/java/com/thealgorithms/geometry/BresenhamLine.java b/src/main/java/com/thealgorithms/geometry/BresenhamLine.java
index 51d9930c0250..9ab69439fdb1 100644
--- a/src/main/java/com/thealgorithms/geometry/BresenhamLine.java
+++ b/src/main/java/com/thealgorithms/geometry/BresenhamLine.java
@@ -11,7 +11,7 @@
*
*
This algorithm uses integer arithmetic to calculate the points,
* making it suitable for rasterization in computer graphics.
- *
+ *
* For more information, please visit {@link https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm}
*/
public final class BresenhamLine {
diff --git a/src/main/java/com/thealgorithms/geometry/ConvexHull.java b/src/main/java/com/thealgorithms/geometry/ConvexHull.java
index 17f400854c64..ac0872187952 100644
--- a/src/main/java/com/thealgorithms/geometry/ConvexHull.java
+++ b/src/main/java/com/thealgorithms/geometry/ConvexHull.java
@@ -12,9 +12,9 @@
/**
* A class providing algorithms to compute the convex hull of a set of points
* using brute-force and recursive methods.
- *
+ *
* Convex hull: The smallest convex polygon that contains all the given points.
- *
+ *
* Algorithms provided:
* 1. Brute-Force Method
* 2. Recursive (Divide-and-Conquer) Method
diff --git a/src/main/java/com/thealgorithms/geometry/GrahamScan.java b/src/main/java/com/thealgorithms/geometry/GrahamScan.java
index 1a373cf315a2..4c526c76910c 100644
--- a/src/main/java/com/thealgorithms/geometry/GrahamScan.java
+++ b/src/main/java/com/thealgorithms/geometry/GrahamScan.java
@@ -9,7 +9,7 @@
* 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
diff --git a/src/main/java/com/thealgorithms/geometry/MidpointEllipse.java b/src/main/java/com/thealgorithms/geometry/MidpointEllipse.java
index fbd53c679960..0284c97cac2e 100644
--- a/src/main/java/com/thealgorithms/geometry/MidpointEllipse.java
+++ b/src/main/java/com/thealgorithms/geometry/MidpointEllipse.java
@@ -20,8 +20,8 @@ private MidpointEllipse() {
*
* @param centerX the x-coordinate of the center of the ellipse
* @param centerY the y-coordinate of the center of the ellipse
- * @param a the length of the semi-major axis (horizontal radius)
- * @param b the length of the semi-minor axis (vertical radius)
+ * @param a the length of the semi-major axis (horizontal radius)
+ * @param b the length of the semi-minor axis (vertical radius)
* @return a list of points (represented as int arrays) that form the ellipse
*/
public static List drawEllipse(int centerX, int centerY, int a, int b) {
@@ -58,11 +58,11 @@ public static List drawEllipse(int centerX, int centerY, int a, int b) {
/**
* Computes points of a non-degenerate ellipse using the Midpoint Ellipse Algorithm.
*
- * @param points the list to which points will be added
- * @param centerX the x-coordinate of the center of the ellipse
- * @param centerY the y-coordinate of the center of the ellipse
- * @param a the length of the semi-major axis (horizontal radius)
- * @param b the length of the semi-minor axis (vertical radius)
+ * @param points the list to which points will be added
+ * @param centerX the x-coordinate of the center of the ellipse
+ * @param centerY the y-coordinate of the center of the ellipse
+ * @param a the length of the semi-major axis (horizontal radius)
+ * @param b the length of the semi-minor axis (vertical radius)
*/
private static void computeEllipsePoints(Collection points, int centerX, int centerY, int a, int b) {
int x = 0; // Initial x-coordinate
@@ -116,11 +116,11 @@ private static void computeEllipsePoints(Collection points, int centerX,
/**
* Adds points for all four quadrants of the ellipse based on symmetry.
*
- * @param points the list to which points will be added
- * @param centerX the x-coordinate of the center of the ellipse
- * @param centerY the y-coordinate of the center of the ellipse
- * @param x the x-coordinate relative to the center
- * @param y the y-coordinate relative to the center
+ * @param points the list to which points will be added
+ * @param centerX the x-coordinate of the center of the ellipse
+ * @param centerY the y-coordinate of the center of the ellipse
+ * @param x the x-coordinate relative to the center
+ * @param y the y-coordinate relative to the center
*/
private static void addEllipsePoints(Collection points, int centerX, int centerY, int x, int y) {
points.add(new int[] {centerX + x, centerY + y});
diff --git a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
index 87d4e89d2c8c..fa6e59ec69b7 100644
--- a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
+++ b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
@@ -8,7 +8,7 @@
* 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.
+ * @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/greedyalgorithms/ActivitySelection.java b/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java
index 54ba4eb650a8..c12081b1bf19 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.
- *
+ *
* 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.
@@ -22,7 +22,7 @@ private ActivitySelection() {
* @param startTimes Array containing the start times of the activities.
* @param endTimes Array containing the end times of the activities.
* @return A list of indices representing the selected activities that can be
- * performed without overlap.
+ * performed without overlap.
*/
public static ArrayList activitySelection(int[] startTimes, int[] endTimes) {
int n = startTimes.length;
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/BinaryAddition.java b/src/main/java/com/thealgorithms/greedyalgorithms/BinaryAddition.java
index 074c76b9f33f..90acb345d617 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/BinaryAddition.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/BinaryAddition.java
@@ -8,8 +8,9 @@
public class BinaryAddition {
/**
* Computes the sum of two binary characters and a carry.
- * @param a First binary character ('0' or '1').
- * @param b Second binary character ('0' or '1').
+ *
+ * @param a First binary character ('0' or '1').
+ * @param b Second binary character ('0' or '1').
* @param carry The carry from the previous operation ('0' or '1').
* @return The sum as a binary character ('0' or '1').
*/
@@ -26,10 +27,12 @@ public char sum(char a, char b, char carry) {
}
return count % 2 == 0 ? '0' : '1';
}
+
/**
* Computes the carry for the next higher bit from two binary characters and a carry.
- * @param a First binary character ('0' or '1').
- * @param b Second binary character ('0' or '1').
+ *
+ * @param a First binary character ('0' or '1').
+ * @param b Second binary character ('0' or '1').
* @param carry The carry from the previous operation ('0' or '1').
* @return The carry for the next bit ('0' or '1').
*/
@@ -46,8 +49,10 @@ public char carry(char a, char b, char carry) {
}
return count >= 2 ? '1' : '0';
}
+
/**
* Adds two binary strings and returns their sum as a binary string.
+ *
* @param a First binary string.
* @param b Second binary string.
* @return Binary string representing the sum of the two binary inputs.
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java b/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java
index 8054581d21d7..514011595ef0 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java
@@ -9,6 +9,7 @@
public final class CoinChange {
private CoinChange() {
}
+
// Function to solve the coin change problem
public static ArrayList coinChangeProblem(int amount) {
// Define an array of coin denominations in descending order
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/DigitSeparation.java b/src/main/java/com/thealgorithms/greedyalgorithms/DigitSeparation.java
index bee5f98cd2ee..f30dd81f2e02 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/DigitSeparation.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/DigitSeparation.java
@@ -10,8 +10,10 @@
public class DigitSeparation {
public DigitSeparation() {
}
+
/**
* Separates the digits of a large positive number into a list in reverse order.
+ *
* @param largeNumber The large number to separate digits from.
* @return A list of digits in reverse order.
*/
@@ -27,8 +29,10 @@ public List digitSeparationReverseOrder(long largeNumber) {
}
return result;
}
+
/**
* Separates the digits of a large positive number into a list in forward order.
+ *
* @param largeNumber The large number to separate digits from.
* @return A list of digits in forward order.
*/
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
index 9535a7c6190e..b69052b23602 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java
@@ -7,11 +7,11 @@
* 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
*/
public final class FractionalKnapsack {
@@ -21,8 +21,8 @@ private FractionalKnapsack() {
/**
* Computes the maximum value that can be accommodated in a knapsack of a given capacity.
*
- * @param weight an array of integers representing the weights of the items
- * @param value an array of integers representing the values of the items
+ * @param weight an array of integers representing the weights of the items
+ * @param value an array of integers representing the values of the items
* @param capacity an integer representing the maximum weight capacity of the knapsack
* @return the maximum value that can be obtained by including the items in the knapsack
*/
diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/MergeIntervals.java b/src/main/java/com/thealgorithms/greedyalgorithms/MergeIntervals.java
index 07bd0b73326f..14ddc7261f8b 100644
--- a/src/main/java/com/thealgorithms/greedyalgorithms/MergeIntervals.java
+++ b/src/main/java/com/thealgorithms/greedyalgorithms/MergeIntervals.java
@@ -7,7 +7,7 @@
/**
* Problem Statement:
* Given an array of intervals where intervals[i] = [starti, endi].
- *
+ *
* 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,10 +33,10 @@ 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}}
+ *
+ * Example:
+ * Input: {{1, 3}, {2, 6}, {8, 10}, {15, 18}}
+ * Output: {{1, 6}, {8, 10}, {15, 18}}
*/
public static int[][] merge(int[][] intervals) {
// Sort the intervals by their start time (ascending order)
diff --git a/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java b/src/main/java/com/thealgorithms/lineclipping/CohenSutherland.java
index 6e8611b86332..c66d09a34a11 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
- *
+ *
* 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.
diff --git a/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java b/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
index 723e2bb2fbf9..cc16c4e0905a 100644
--- a/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
+++ b/src/main/java/com/thealgorithms/lineclipping/LiangBarsky.java
@@ -6,16 +6,16 @@
/**
* @author shikarisohan
* @since 10/5/24
- *
- * * The Liang-Barsky line clipping algorithm is an efficient algorithm for
- * * line clipping against a rectangular window. It is based on the parametric
- * * equation of a line and checks the intersections of the line with the
- * * window boundaries. This algorithm calculates the intersection points,
- * * if any, and returns the clipped line that lies inside the window.
- * *
- * * Reference:
- * * https://en.wikipedia.org/wiki/Liang%E2%80%93Barsky_algorithm
- *
+ *
+ * * The Liang-Barsky line clipping algorithm is an efficient algorithm for
+ * * line clipping against a rectangular window. It is based on the parametric
+ * * equation of a line and checks the intersections of the line with the
+ * * window boundaries. This algorithm calculates the intersection points,
+ * * 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.
diff --git a/src/main/java/com/thealgorithms/maths/ADTFraction.java b/src/main/java/com/thealgorithms/maths/ADTFraction.java
index a85ef09079c9..9527ebf34556 100644
--- a/src/main/java/com/thealgorithms/maths/ADTFraction.java
+++ b/src/main/java/com/thealgorithms/maths/ADTFraction.java
@@ -61,7 +61,7 @@ public ADTFraction reciprocal() {
* Calculates the result of the fraction.
*
* @return The numerical result of the division between {@code numerator} and {@code
- * denominator}
+ * denominator}
*/
public float value() {
return (float) this.numerator / this.denominator;
diff --git a/src/main/java/com/thealgorithms/maths/AmicableNumber.java b/src/main/java/com/thealgorithms/maths/AmicableNumber.java
index b30831bfdc58..f77b5a3f359b 100644
--- a/src/main/java/com/thealgorithms/maths/AmicableNumber.java
+++ b/src/main/java/com/thealgorithms/maths/AmicableNumber.java
@@ -22,6 +22,7 @@
public final class AmicableNumber {
private AmicableNumber() {
}
+
/**
* Finds all the amicable numbers in a given range.
*
diff --git a/src/main/java/com/thealgorithms/maths/Armstrong.java b/src/main/java/com/thealgorithms/maths/Armstrong.java
index ff4ae027a0b7..91b8f2e47e6b 100644
--- a/src/main/java/com/thealgorithms/maths/Armstrong.java
+++ b/src/main/java/com/thealgorithms/maths/Armstrong.java
@@ -4,7 +4,7 @@
* This class checks whether a given number is an Armstrong number or not.
* An Armstrong number is a number that is equal to the sum of its own digits,
* each raised to the power of the number of digits.
- *
+ *
* 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/AutomorphicNumber.java b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
index 31f81da63f03..53c80b3b5e24 100644
--- a/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
+++ b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
@@ -1,6 +1,7 @@
package com.thealgorithms.maths;
import java.math.BigInteger;
+
/**
* Automorphic Number
* A number is said to be an Automorphic, if it is present in the last digit(s)
@@ -17,7 +18,7 @@ private AutomorphicNumber() {
*
* @param n The number to be checked
* @return {@code true} if {@code a} is Automorphic number, otherwise
- * {@code false}
+ * {@code false}
*/
public static boolean isAutomorphic(long n) {
if (n < 0) {
@@ -39,7 +40,7 @@ public static boolean isAutomorphic(long n) {
*
* @param n The number to be checked
* @return {@code true} if {@code a} is Automorphic number, otherwise
- * {@code false}
+ * {@code false}
*/
public static boolean isAutomorphic2(long n) {
if (n < 0) {
@@ -54,7 +55,7 @@ public static boolean isAutomorphic2(long n) {
*
* @param s The number in String to be checked
* @return {@code true} if {@code a} is Automorphic number, otherwise
- * {@code false}
+ * {@code false}
*/
public static boolean isAutomorphic3(String s) {
BigInteger n = new BigInteger(s);
diff --git a/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java b/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java
index faec049b08a7..9be4b9e0911c 100644
--- a/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java
+++ b/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java
@@ -20,7 +20,7 @@ private BinomialCoefficient() {
* @param totalObjects Total number of objects
* @param numberOfObjects Number of objects to be chosen from total_objects
* @return number of ways in which no_of_objects objects can be chosen from total_objects
- * objects
+ * objects
*/
public static int binomialCoefficient(int totalObjects, int numberOfObjects) {
diff --git a/src/main/java/com/thealgorithms/maths/ChineseRemainderTheorem.java b/src/main/java/com/thealgorithms/maths/ChineseRemainderTheorem.java
index c26e67cffb59..37e5b9a4c56c 100644
--- a/src/main/java/com/thealgorithms/maths/ChineseRemainderTheorem.java
+++ b/src/main/java/com/thealgorithms/maths/ChineseRemainderTheorem.java
@@ -4,8 +4,7 @@
/**
* @brief Implementation of the Chinese Remainder Theorem (CRT) algorithm
- * @details
- * The Chinese Remainder Theorem (CRT) is used to solve systems of
+ * @details The Chinese Remainder Theorem (CRT) is used to solve systems of
* simultaneous congruences. Given several pairwise coprime moduli
* and corresponding remainders, the algorithm finds the smallest
* positive solution.
@@ -15,10 +14,10 @@ private ChineseRemainderTheorem() {
}
/**
- * @brief Solves the Chinese Remainder Theorem problem.
* @param remainders The list of remainders.
- * @param moduli The list of pairwise coprime moduli.
+ * @param moduli The list of pairwise coprime moduli.
* @return The smallest positive solution that satisfies all the given congruences.
+ * @brief Solves the Chinese Remainder Theorem problem.
*/
public static int solveCRT(List remainders, List moduli) {
int product = 1;
@@ -46,11 +45,11 @@ public static int solveCRT(List remainders, List moduli) {
}
/**
- * @brief Computes the modular inverse of a number with respect to a modulus using
- * the Extended Euclidean Algorithm.
* @param a The number for which to find the inverse.
* @param m The modulus.
* @return The modular inverse of a modulo m.
+ * @brief Computes the modular inverse of a number with respect to a modulus using
+ * the Extended Euclidean Algorithm.
*/
private static int modInverse(int a, int m) {
int m0 = m;
diff --git a/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java b/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
index 87fc5af57b8d..656b542dfdd7 100644
--- a/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
+++ b/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java
@@ -17,7 +17,7 @@ private CircularConvolutionFFT() {
/**
* This method pads the signal with zeros until it reaches the new size.
*
- * @param x The signal to be padded.
+ * @param x The signal to be padded.
* @param newSize The new size of the signal.
*/
private static void padding(Collection x, int newSize) {
diff --git a/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java b/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
index ed1ba1bbefc3..6f45b33fa109 100644
--- a/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
+++ b/src/main/java/com/thealgorithms/maths/ConvolutionFFT.java
@@ -17,7 +17,7 @@ private ConvolutionFFT() {
/**
* This method pads the signal with zeros until it reaches the new size.
*
- * @param x The signal to be padded.
+ * @param x The signal to be padded.
* @param newSize The new size of the signal.
*/
private static void padding(Collection x, int newSize) {
@@ -61,7 +61,7 @@ public static ArrayList convolutionFFT(ArrayList a, Ar
}
FFT.fft(convolved, true); // IFFT
convolved.subList(convolvedSize, convolved.size()).clear(); // Remove the remaining zeros after the convolvedSize. These extra zeros came
- // from
+ // from
// paddingPowerOfTwo() method inside the fft() method.
return convolved;
diff --git a/src/main/java/com/thealgorithms/maths/DigitalRoot.java b/src/main/java/com/thealgorithms/maths/DigitalRoot.java
index e8f5305c7569..1719b24a0048 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
@@ -41,7 +41,7 @@ private DigitalRoot() {
public static int digitalRoot(int n) {
if (single(n) <= 9) { // If n is already single digit than simply call single method and
- // return the value
+ // return the value
return single(n);
} else {
return digitalRoot(single(n));
diff --git a/src/main/java/com/thealgorithms/maths/DudeneyNumber.java b/src/main/java/com/thealgorithms/maths/DudeneyNumber.java
index acf1e55d49c8..3d9fa1cee38f 100644
--- a/src/main/java/com/thealgorithms/maths/DudeneyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/DudeneyNumber.java
@@ -1,8 +1,8 @@
/**
* A number is said to be Dudeney if the sum of the digits, is the cube root of the entered number.
* Example- Let the number be 512, its sum of digits is 5+1+2=8. The cube root of 512 is also 8.
- * Since, the sum of the digits is equal to the cube root of the entered number;
- * it is a Dudeney Number.
+ * Since, the sum of the digits is equal to the cube root of the entered number;
+ * it is a Dudeney Number.
*/
package com.thealgorithms.maths;
diff --git a/src/main/java/com/thealgorithms/maths/EulerMethod.java b/src/main/java/com/thealgorithms/maths/EulerMethod.java
index 3663b6c534aa..4364934f4d54 100644
--- a/src/main/java/com/thealgorithms/maths/EulerMethod.java
+++ b/src/main/java/com/thealgorithms/maths/EulerMethod.java
@@ -49,9 +49,9 @@ public static void main(String[] args) {
* calculates the next y-value based on the current value of x, y and the
* stepSize the console.
*
- * @param xCurrent Current x-value.
- * @param stepSize Step-size on the x-axis.
- * @param yCurrent Current y-value.
+ * @param xCurrent Current x-value.
+ * @param stepSize Step-size on the x-axis.
+ * @param yCurrent Current y-value.
* @param differentialEquation The differential equation to be solved.
* @return The next y-value.
*/
@@ -66,10 +66,10 @@ public static double eulerStep(double xCurrent, double stepSize, double yCurrent
* Loops through all the steps until xEnd is reached, adds a point for each
* step and then returns all the points
*
- * @param xStart First x-value.
- * @param xEnd Last x-value.
- * @param stepSize Step-size on the x-axis.
- * @param yStart First y-value.
+ * @param xStart First x-value.
+ * @param xEnd Last x-value.
+ * @param stepSize Step-size on the x-axis.
+ * @param yStart First y-value.
* @param differentialEquation The differential equation to be solved.
* @return The points constituting the solution of the differential
* equation.
diff --git a/src/main/java/com/thealgorithms/maths/FFT.java b/src/main/java/com/thealgorithms/maths/FFT.java
index 91754bd1a80b..117d36deedb9 100644
--- a/src/main/java/com/thealgorithms/maths/FFT.java
+++ b/src/main/java/com/thealgorithms/maths/FFT.java
@@ -187,8 +187,9 @@ public double imaginary() {
* 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 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
*/
@@ -263,7 +264,7 @@ public static ArrayList inverseFFT(int n, boolean inverse, ArrayList x, boolean inverse) {
diff --git a/src/main/java/com/thealgorithms/maths/FactorialRecursion.java b/src/main/java/com/thealgorithms/maths/FactorialRecursion.java
index d9bafd1e39e9..743d8afd03fe 100644
--- a/src/main/java/com/thealgorithms/maths/FactorialRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/FactorialRecursion.java
@@ -3,6 +3,7 @@
public final class FactorialRecursion {
private FactorialRecursion() {
}
+
/**
* Recursive FactorialRecursion Method
*
diff --git a/src/main/java/com/thealgorithms/maths/FastExponentiation.java b/src/main/java/com/thealgorithms/maths/FastExponentiation.java
index 27f49e27ff30..8bfce27b34f1 100644
--- a/src/main/java/com/thealgorithms/maths/FastExponentiation.java
+++ b/src/main/java/com/thealgorithms/maths/FastExponentiation.java
@@ -14,7 +14,7 @@
*
*
* 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}
*/
public final class FastExponentiation {
@@ -33,11 +33,11 @@ private FastExponentiation() {
* the exponent at each step. It multiplies the base to the result when the exponent is odd.
*
* @param base the base number to be raised to the power of exp
- * @param exp the exponent to which the base is raised
- * @param mod the modulus to ensure the result does not overflow
- * @return (base^exp) % mod
+ * @param exp the exponent to which the base is raised
+ * @param mod the modulus to ensure the result does not overflow
+ * @return (base ^ exp) % mod
* @throws IllegalArgumentException if the modulus is less than or equal to 0
- * @throws ArithmeticException if the exponent is negative (not supported in this implementation)
+ * @throws ArithmeticException if the exponent is negative (not supported in this implementation)
*/
public static long fastExponentiation(long base, long exp, long mod) {
if (mod <= 0) {
diff --git a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
index 01a52b913d30..77ff463104f5 100644
--- a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
+++ b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
@@ -8,11 +8,12 @@
public final class FastInverseSqrt {
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..68b71b5eeec3 100644
--- a/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java
+++ b/src/main/java/com/thealgorithms/maths/FibonacciNumberCheck.java
@@ -8,12 +8,13 @@
public final class FibonacciNumberCheck {
private FibonacciNumberCheck() {
}
+
/**
* Check if a number is perfect square number
*
* @param number the number to be checked
* @return true if {@code number} is a perfect square, otherwise
- * false
+ * false
*/
public static boolean isPerfectSquare(long number) {
long sqrt = (long) Math.sqrt(number);
@@ -26,7 +27,7 @@ public static boolean isPerfectSquare(long number) {
*
* @param number the number
* @return true if {@code number} is a Fibonacci number, otherwise
- * false
+ * false
* @link https://en.wikipedia.org/wiki/Fibonacci_number#Identification
*/
public static boolean isFibonacciNumber(long number) {
diff --git a/src/main/java/com/thealgorithms/maths/FindMax.java b/src/main/java/com/thealgorithms/maths/FindMax.java
index 0ff2bdd191ac..cbb9dc9af545 100644
--- a/src/main/java/com/thealgorithms/maths/FindMax.java
+++ b/src/main/java/com/thealgorithms/maths/FindMax.java
@@ -5,11 +5,10 @@ private FindMax() {
}
/**
- * @brief finds the maximum value stored in the input array
- *
* @param array the input array
- * @exception IllegalArgumentException input array is empty
* @return the maximum value stored in the input array
+ * @throws IllegalArgumentException input array is empty
+ * @brief finds the maximum value stored in the input array
*/
public static int findMax(final int[] array) {
int n = array.length;
diff --git a/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java b/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java
index 950a0ebe0085..989a497fa85d 100644
--- a/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java
@@ -4,12 +4,13 @@ public final class FindMaxRecursion {
private FindMaxRecursion() {
}
+
/**
* Get max of an array using divide and conquer algorithm
*
* @param array contains elements
- * @param low the index of the first element
- * @param high the index of the last element
+ * @param low the index of the first element
+ * @param high the index of the last element
* @return max of {@code array}
*/
public static int max(final int[] array, final int low, final int high) {
diff --git a/src/main/java/com/thealgorithms/maths/FindMin.java b/src/main/java/com/thealgorithms/maths/FindMin.java
index 76fa2e815ee0..62a938d72870 100644
--- a/src/main/java/com/thealgorithms/maths/FindMin.java
+++ b/src/main/java/com/thealgorithms/maths/FindMin.java
@@ -5,11 +5,10 @@ private FindMin() {
}
/**
- * @brief finds the minimum value stored in the input array
- *
* @param array the input array
- * @exception IllegalArgumentException input array is empty
* @return the mimum value stored in the input array
+ * @throws IllegalArgumentException input array is empty
+ * @brief finds the minimum value stored in the input array
*/
public static int findMin(final int[] array) {
if (array.length == 0) {
diff --git a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java
index a2cf1b36d6cb..3027b93b7d31 100644
--- a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java
@@ -9,8 +9,8 @@ private FindMinRecursion() {
* Get min of an array using divide and conquer algorithm
*
* @param array contains elements
- * @param low the index of the first element
- * @param high the index of the last element
+ * @param low the index of the first element
+ * @param high the index of the last element
* @return min of {@code array}
*/
diff --git a/src/main/java/com/thealgorithms/maths/GCD.java b/src/main/java/com/thealgorithms/maths/GCD.java
index df27516367b2..307d6752974e 100644
--- a/src/main/java/com/thealgorithms/maths/GCD.java
+++ b/src/main/java/com/thealgorithms/maths/GCD.java
@@ -1,12 +1,12 @@
package com.thealgorithms.maths;
/**
- * This class provides methods to compute the Greatest Common Divisor (GCD) of two or more integers.
- *
+ * 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.
*
@@ -18,6 +18,7 @@
* int result2 = GCD.gcd(48, 18, 30);
* System.out.println("GCD of 48, 18, and 30: " + result2); // Output: 6
*
+ *
* @author Oskar Enmalm 3/10/17
*/
public final class GCD {
@@ -49,10 +50,9 @@ public static int gcd(int num1, int num2) {
}
/**
- * @brief computes gcd of an array of numbers
- *
* @param numbers the input array
* @return gcd of all of the numbers in the input array
+ * @brief computes gcd of an array of numbers
*/
public static int gcd(int... numbers) {
int result = 0;
diff --git a/src/main/java/com/thealgorithms/maths/HarshadNumber.java b/src/main/java/com/thealgorithms/maths/HarshadNumber.java
index 5792e925a8aa..30c93c3b3b26 100644
--- a/src/main/java/com/thealgorithms/maths/HarshadNumber.java
+++ b/src/main/java/com/thealgorithms/maths/HarshadNumber.java
@@ -11,7 +11,7 @@ private HarshadNumber() {
*
* @param n The number to be checked
* @return {@code true} if {@code a} is Harshad number, otherwise
- * {@code false}
+ * {@code false}
*/
public static boolean isHarshad(long n) {
if (n <= 0) {
@@ -33,7 +33,7 @@ public static boolean isHarshad(long n) {
*
* @param s The number in String to be checked
* @return {@code true} if {@code a} is Harshad number, otherwise
- * {@code false}
+ * {@code false}
*/
public static boolean isHarshad(String s) {
final Long n = Long.valueOf(s);
diff --git a/src/main/java/com/thealgorithms/maths/JosephusProblem.java b/src/main/java/com/thealgorithms/maths/JosephusProblem.java
index 98d839011a7f..75bb19bceb1a 100644
--- a/src/main/java/com/thealgorithms/maths/JosephusProblem.java
+++ b/src/main/java/com/thealgorithms/maths/JosephusProblem.java
@@ -5,18 +5,18 @@
* numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend
* brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings
* you to the 1st friend.
-
- The rules of the game are as follows:
-
- 1.Start at the 1st friend.
- 2.Count the next k friends in the clockwise direction including the friend you started at.
- The counting wraps around the circle and may count some friends more than once. 3.The last friend
- you counted leaves the circle and loses the game. 4.If there is still more than one friend in the
- circle, go back to step 2 starting from the friend immediately clockwise of the friend who just
- lost and repeat. 5.Else, the last friend in the circle wins the game.
-
- @author Kunal
- */
+ *
+ * The rules of the game are as follows:
+ *
+ * 1.Start at the 1st friend.
+ * 2.Count the next k friends in the clockwise direction including the friend you started at.
+ * The counting wraps around the circle and may count some friends more than once. 3.The last friend
+ * you counted leaves the circle and loses the game. 4.If there is still more than one friend in the
+ * circle, go back to step 2 starting from the friend immediately clockwise of the friend who just
+ * lost and repeat. 5.Else, the last friend in the circle wins the game.
+ *
+ * @author Kunal
+ */
public final class JosephusProblem {
private JosephusProblem() {
}
diff --git a/src/main/java/com/thealgorithms/maths/KaratsubaMultiplication.java b/src/main/java/com/thealgorithms/maths/KaratsubaMultiplication.java
index 298fcb7e85f8..779f1ed874ce 100644
--- a/src/main/java/com/thealgorithms/maths/KaratsubaMultiplication.java
+++ b/src/main/java/com/thealgorithms/maths/KaratsubaMultiplication.java
@@ -24,7 +24,7 @@
* Then, the product of x and y can be expressed as:
* x * y = (a * c) * 10^(2*m) + ((a * d) + (b * c)) * 10^m + (b * d)
*
- *
+ *
* The Karatsuba algorithm calculates this more efficiently by reducing the number of
* multiplications from four to three by using the identity:
*
diff --git a/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java b/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java
index 03f18aca786f..e02ddab53596 100644
--- a/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java
@@ -2,9 +2,9 @@
/**
* Utility class for checking if a number is a Krishnamurthy number.
- *
+ *
* A Krishnamurthy number (also known as a Strong number) is a number whose sum of the factorials of its digits is equal to the number itself.
- *
+ *
* For example, 145 is a Krishnamurthy number because 1! + 4! + 5! = 1 + 24 + 120 = 145.
* Example usage:
*
diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
index 9ec11e9b3220..11f3e1141cac 100644
--- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
+++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java
@@ -4,6 +4,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 {
diff --git a/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java b/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java
index c0f55f5e3485..04d21434d4f0 100644
--- a/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java
+++ b/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java
@@ -20,8 +20,8 @@ private LiouvilleLambdaFunction() {
* This method returns λ(n) of given number n
*
* @param number Integer value which λ(n) is to be calculated
- * @return 1 when number has even number of prime factors
- * -1 when number has odd number of prime factors
+ * @return 1 when number has even number of prime factors
+ * -1 when number has odd number of prime factors
* @throws IllegalArgumentException when number is negative
*/
static int liouvilleLambda(int number) {
diff --git a/src/main/java/com/thealgorithms/maths/LongDivision.java b/src/main/java/com/thealgorithms/maths/LongDivision.java
index 45e97b1c14c3..7a04a49f6b3a 100644
--- a/src/main/java/com/thealgorithms/maths/LongDivision.java
+++ b/src/main/java/com/thealgorithms/maths/LongDivision.java
@@ -11,6 +11,7 @@
public final class LongDivision {
private LongDivision() {
}
+
public static int divide(int dividend, int divisor) {
long newDividend1 = dividend;
long newDivisor1 = divisor;
diff --git a/src/main/java/com/thealgorithms/maths/MatrixRank.java b/src/main/java/com/thealgorithms/maths/MatrixRank.java
index 7a628b92dccb..b91ac58b168d 100644
--- a/src/main/java/com/thealgorithms/maths/MatrixRank.java
+++ b/src/main/java/com/thealgorithms/maths/MatrixRank.java
@@ -21,10 +21,9 @@ private MatrixRank() {
private static final double EPSILON = 1e-10;
/**
- * @brief Computes the rank of the input matrix
- *
* @param matrix The input matrix
* @return The rank of the input matrix
+ * @brief Computes the rank of the input matrix
*/
public static int computeRank(double[][] matrix) {
validateInputMatrix(matrix);
@@ -88,11 +87,10 @@ private static boolean hasValidRows(double[][] matrix) {
}
/**
- * @brief Checks if the input matrix is a jagged matrix.
- * Jagged matrix is a matrix where the number of columns in each row is not the same.
- *
* @param matrix The input matrix
* @return True if the input matrix is a jagged matrix, false otherwise
+ * @brief Checks if the input matrix is a jagged matrix.
+ * Jagged matrix is a matrix where the number of columns in each row is not the same.
*/
private static boolean isJaggedMatrix(double[][] matrix) {
int numColumns = matrix[0].length;
@@ -105,16 +103,15 @@ private static boolean isJaggedMatrix(double[][] matrix) {
}
/**
+ * @param matrix The input matrix
+ * @param rowMarked An array indicating which rows have been marked
+ * @param colIndex The column index
+ * @return The pivot row index, or the number of rows if no suitable pivot row was found
* @brief The pivot row is the row in the matrix that is used to eliminate other rows and reduce the matrix to its row echelon form.
* The pivot row is selected as the first row (from top to bottom) where the value in the current column (the pivot column) is not zero.
* This row is then used to "eliminate" other rows, by subtracting multiples of the pivot row from them, so that all other entries in the pivot column become zero.
* This process is repeated for each column, each time selecting a new pivot row, until the matrix is in row echelon form.
* The number of pivot rows (rows with a leading entry, or pivot) then gives the rank of the matrix.
- *
- * @param matrix The input matrix
- * @param rowMarked An array indicating which rows have been marked
- * @param colIndex The column index
- * @return The pivot row index, or the number of rows if no suitable pivot row was found
*/
private static int findPivotRow(double[][] matrix, boolean[] rowMarked, int colIndex) {
int numRows = matrix.length;
@@ -127,12 +124,11 @@ private static int findPivotRow(double[][] matrix, boolean[] rowMarked, int colI
}
/**
- * @brief This method divides all values in the pivot row by the value in the given column.
- * This ensures that the pivot value itself will be 1, which simplifies further calculations.
- *
- * @param matrix The input matrix
+ * @param matrix The input matrix
* @param pivotRow The pivot row index
* @param colIndex The column index
+ * @brief This method divides all values in the pivot row by the value in the given column.
+ * This ensures that the pivot value itself will be 1, which simplifies further calculations.
*/
private static void normalizePivotRow(double[][] matrix, int pivotRow, int colIndex) {
int numColumns = matrix[0].length;
@@ -142,13 +138,12 @@ private static void normalizePivotRow(double[][] matrix, int pivotRow, int colIn
}
/**
+ * @param matrix The input matrix
+ * @param pivotRow The pivot row index
+ * @param colIndex The column index
* @brief This method subtracts multiples of the pivot row from all other rows,
* so that all values in the given column of other rows will be zero.
* This is a key step in reducing the matrix to row echelon form.
- *
- * @param matrix The input matrix
- * @param pivotRow The pivot row index
- * @param colIndex The column index
*/
private static void eliminateRows(double[][] matrix, int pivotRow, int colIndex) {
int numRows = matrix.length;
diff --git a/src/main/java/com/thealgorithms/maths/MaxValue.java b/src/main/java/com/thealgorithms/maths/MaxValue.java
index d88291060f51..a82a61137afd 100644
--- a/src/main/java/com/thealgorithms/maths/MaxValue.java
+++ b/src/main/java/com/thealgorithms/maths/MaxValue.java
@@ -3,6 +3,7 @@
public final class MaxValue {
private MaxValue() {
}
+
/**
* Returns the greater of two {@code int} values. That is, the result is the
* argument closer to the value of {@link Integer#MAX_VALUE}. If the
diff --git a/src/main/java/com/thealgorithms/maths/Means.java b/src/main/java/com/thealgorithms/maths/Means.java
index dccc820b172e..9ce230c656d7 100644
--- a/src/main/java/com/thealgorithms/maths/Means.java
+++ b/src/main/java/com/thealgorithms/maths/Means.java
@@ -14,10 +14,10 @@ private Means() {
}
/**
- * @brief computes the [Arithmetic Mean](https://en.wikipedia.org/wiki/Arithmetic_mean) of the input
* @param numbers the input numbers
- * @throws IllegalArgumentException empty input
* @return the arithmetic mean of the input numbers
+ * @throws IllegalArgumentException empty input
+ * @brief computes the [Arithmetic Mean](https://en.wikipedia.org/wiki/Arithmetic_mean) of the input
*/
public static Double arithmetic(final Iterable numbers) {
checkIfNotEmpty(numbers);
@@ -25,10 +25,10 @@ public static Double arithmetic(final Iterable numbers) {
}
/**
- * @brief computes the [Geometric Mean](https://en.wikipedia.org/wiki/Geometric_mean) of the input
* @param numbers the input numbers
- * @throws IllegalArgumentException empty input
* @return the geometric mean of the input numbers
+ * @throws IllegalArgumentException empty input
+ * @brief computes the [Geometric Mean](https://en.wikipedia.org/wiki/Geometric_mean) of the input
*/
public static Double geometric(final Iterable numbers) {
checkIfNotEmpty(numbers);
@@ -36,10 +36,10 @@ public static Double geometric(final Iterable numbers) {
}
/**
- * @brief computes the [Harmonic Mean](https://en.wikipedia.org/wiki/Harmonic_mean) of the input
* @param numbers the input numbers
- * @throws IllegalArgumentException empty input
* @return the harmonic mean of the input numbers
+ * @throws IllegalArgumentException empty input
+ * @brief computes the [Harmonic Mean](https://en.wikipedia.org/wiki/Harmonic_mean) of the input
*/
public static Double harmonic(final Iterable numbers) {
checkIfNotEmpty(numbers);
diff --git a/src/main/java/com/thealgorithms/maths/Median.java b/src/main/java/com/thealgorithms/maths/Median.java
index e4daec8fc11a..70ddde444154 100644
--- a/src/main/java/com/thealgorithms/maths/Median.java
+++ b/src/main/java/com/thealgorithms/maths/Median.java
@@ -11,6 +11,7 @@ private Median() {
/**
* Calculate average median
+ *
* @param values sorted numbers to find median of
* @return median of given {@code values}
*/
diff --git a/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java b/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java
index f889213abfcb..2db6bf30d0cd 100644
--- a/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java
+++ b/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java
@@ -14,8 +14,8 @@ private MillerRabinPrimalityCheck() {
*
* @param n Whole number which is tested on primality
* @param k Number of iterations
- * If n is composite then running k iterations of the Miller–Rabin
- * test will declare n probably prime with a probability at most 4^(−k)
+ * If n is composite then running k iterations of the Miller–Rabin
+ * test will declare n probably prime with a probability at most 4^(−k)
* @return true or false whether the given number is probably prime or not
*/
@@ -70,9 +70,8 @@ public static boolean deterministicMillerRabin(long n) { // returns true if n is
* @param a Random number (prime base) to check if it holds certain equality
* @param d Number which holds this equation: 'n - 1 = 2^s * d'
* @param s Number of twos in (n - 1) factorization
- *
* @return true or false whether the numbers hold the equation or not
- * the equations are described on the websites mentioned at the beginning of the class
+ * the equations are described on the websites mentioned at the beginning of the class
*/
private static boolean checkComposite(long n, long a, long d, int s) {
long x = powerModP(a, d, n);
diff --git a/src/main/java/com/thealgorithms/maths/MinValue.java b/src/main/java/com/thealgorithms/maths/MinValue.java
index 88e28e8816c6..2f8e80595e10 100644
--- a/src/main/java/com/thealgorithms/maths/MinValue.java
+++ b/src/main/java/com/thealgorithms/maths/MinValue.java
@@ -3,6 +3,7 @@
public final class MinValue {
private MinValue() {
}
+
/**
* Returns the smaller of two {@code int} values. That is, the result the
* argument closer to the value of {@link Integer#MIN_VALUE}. If the
diff --git a/src/main/java/com/thealgorithms/maths/MobiusFunction.java b/src/main/java/com/thealgorithms/maths/MobiusFunction.java
index 915d0d9a6dae..2ada83729bd3 100644
--- a/src/main/java/com/thealgorithms/maths/MobiusFunction.java
+++ b/src/main/java/com/thealgorithms/maths/MobiusFunction.java
@@ -20,10 +20,10 @@ private MobiusFunction() {
* This method returns μ(n) of given number n
*
* @param number Integer value which μ(n) is to be calculated
- * @return 1 when number is less than or equals 1
- * or number has even number of prime factors
- * 0 when number has repeated prime factor
- * -1 when number has odd number of prime factors
+ * @return 1 when number is less than or equals 1
+ * or number has even number of prime factors
+ * 0 when number has repeated prime factor
+ * -1 when number has odd number of prime factors
*/
static int mobius(int number) {
if (number <= 0) {
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/NthUglyNumber.java b/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
index 6484026c14dd..d41e7f93da83 100644
--- a/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
@@ -8,21 +8,21 @@
/**
* @brief class computing the n-th ugly number (when they are sorted)
* @details the ugly numbers with base [2, 3, 5] are all numbers of the form 2^a*3^b^5^c,
- * where the exponents a, b, c are non-negative integers.
- * Some properties of ugly numbers:
- * - base [2, 3, 5] ugly numbers are the 5-smooth numbers, cf. https://oeis.org/A051037
- * - base [2, 3, 5, 7] ugly numbers are 7-smooth numbers, cf. https://oeis.org/A002473
- * - base [2] ugly numbers are the non-negative powers of 2,
- * - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
+ * where the exponents a, b, c are non-negative integers.
+ * Some properties of ugly numbers:
+ * - base [2, 3, 5] ugly numbers are the 5-smooth numbers, cf. https://oeis.org/A051037
+ * - base [2, 3, 5, 7] ugly numbers are 7-smooth numbers, cf. https://oeis.org/A002473
+ * - base [2] ugly numbers are the non-negative powers of 2,
+ * - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
*/
public class NthUglyNumber {
private ArrayList uglyNumbers = new ArrayList<>(Arrays.asList(1L));
private ArrayList> positions = new ArrayList<>();
/**
- * @brief initialized the object allowing to compute ugly numbers with given base
* @param baseNumbers the given base of ugly numbers
- * @exception IllegalArgumentException baseNumber is empty
+ * @throws IllegalArgumentException baseNumber is empty
+ * @brief initialized the object allowing to compute ugly numbers with given base
*/
NthUglyNumber(final int[] baseNumbers) {
if (baseNumbers.length == 0) {
@@ -36,8 +36,8 @@ public class NthUglyNumber {
/**
* @param n the zero-based-index of the queried ugly number
- * @exception IllegalArgumentException n is negative
* @return the n-th ugly number (starting from index 0)
+ * @throws IllegalArgumentException n is negative
*/
public Long get(final int n) {
if (n < 0) {
diff --git a/src/main/java/com/thealgorithms/maths/NumberOfDigits.java b/src/main/java/com/thealgorithms/maths/NumberOfDigits.java
index fc538196c7da..26732ae93520 100644
--- a/src/main/java/com/thealgorithms/maths/NumberOfDigits.java
+++ b/src/main/java/com/thealgorithms/maths/NumberOfDigits.java
@@ -6,6 +6,7 @@
public final class NumberOfDigits {
private NumberOfDigits() {
}
+
/**
* Find the number of digits in a number.
*
diff --git a/src/main/java/com/thealgorithms/maths/PalindromeNumber.java b/src/main/java/com/thealgorithms/maths/PalindromeNumber.java
index a22d63897b37..55c8a2db7311 100644
--- a/src/main/java/com/thealgorithms/maths/PalindromeNumber.java
+++ b/src/main/java/com/thealgorithms/maths/PalindromeNumber.java
@@ -3,6 +3,7 @@
public final class PalindromeNumber {
private PalindromeNumber() {
}
+
/**
* Check if {@code n} is palindrome number or not
*
diff --git a/src/main/java/com/thealgorithms/maths/PascalTriangle.java b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
index 9a9d4450cb98..452917051399 100644
--- a/src/main/java/com/thealgorithms/maths/PascalTriangle.java
+++ b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
@@ -5,35 +5,34 @@ private PascalTriangle() {
}
/**
- *In mathematics, Pascal's triangle is a triangular array of the binomial coefficients that
- *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.
- *
+ * In mathematics, Pascal's triangle is a triangular array of the binomial coefficients that
+ * 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
- *constructed in the following manner: In row 0 (the topmost row), there is a unique nonzero
- *entry 1. Each entry of each subsequent row is constructed by adding the number above and to
- *the left with the number above and to the right, treating blank entries as 0. For example, the
- *initial number in the first (or any other) row is 1 (the sum of 0 and 1), whereas the numbers
- *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
+ * (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
+ * constructed in the following manner: In row 0 (the topmost row), there is a unique nonzero
+ * entry 1. Each entry of each subsequent row is constructed by adding the number above and to
+ * the left with the number above and to the right, treating blank entries as 0. For example, the
+ * initial number in the first (or any other) row is 1 (the sum of 0 and 1), whereas the numbers
+ * 1 and 3 in the third row are added to produce the number 4 in the fourth row. *
*
*
- * Example:-
- * 1
- * 1 1
- * 1 2 1
- * 1 3 3 1
- * 1 4 6 4 1
- * 1 5 10 10 5 1
- * 1 6 15 20 15 6 1
- * 1 7 21 35 35 21 7 1
- * 1 8 28 56 70 56 28 8 1
+ * link:-https://en.wikipedia.org/wiki/Pascal%27s_triangle
*
+ *
+ * Example:-
+ * 1
+ * 1 1
+ * 1 2 1
+ * 1 3 3 1
+ * 1 4 6 4 1
+ * 1 5 10 10 5 1
+ * 1 6 15 20 15 6 1
+ * 1 7 21 35 35 21 7 1
+ * 1 8 28 56 70 56 28 8 1
*/
public static int[][] pascal(int n) {
diff --git a/src/main/java/com/thealgorithms/maths/PerfectNumber.java b/src/main/java/com/thealgorithms/maths/PerfectNumber.java
index 2a935b067094..1c84173925ea 100644
--- a/src/main/java/com/thealgorithms/maths/PerfectNumber.java
+++ b/src/main/java/com/thealgorithms/maths/PerfectNumber.java
@@ -5,7 +5,7 @@
* 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
*/
public final class PerfectNumber {
diff --git a/src/main/java/com/thealgorithms/maths/Perimeter.java b/src/main/java/com/thealgorithms/maths/Perimeter.java
index f8aa1876d388..84639b517cea 100644
--- a/src/main/java/com/thealgorithms/maths/Perimeter.java
+++ b/src/main/java/com/thealgorithms/maths/Perimeter.java
@@ -10,7 +10,7 @@ private Perimeter() {
* Examples of regular polygon are Equilateral Triangle, Square, Regular Pentagon, Regular
* Hexagon.
*
- * @param n for number of sides.
+ * @param n for number of sides.
* @param side for length of each side.
* @return Perimeter of given polygon
*/
@@ -40,7 +40,7 @@ public static float perimeterIrregularPolygon(float side1, float side2, float si
/**
* Calculate the Perimeter of rectangle
*
- * @param length for length of rectangle
+ * @param length for length of rectangle
* @param breadth for breadth of rectangle
* @return Perimeter of given rectangle
*/
diff --git a/src/main/java/com/thealgorithms/maths/PiNilakantha.java b/src/main/java/com/thealgorithms/maths/PiNilakantha.java
index 6d43f134c94c..0711eae1235e 100644
--- a/src/main/java/com/thealgorithms/maths/PiNilakantha.java
+++ b/src/main/java/com/thealgorithms/maths/PiNilakantha.java
@@ -17,9 +17,9 @@ public static void main(String[] args) {
/**
* @param iterations number of times the infinite series gets repeated Pi
- * get more accurate the higher the value of iterations is Values from 0 up
- * to 500 are allowed since double precision is not sufficient for more than
- * about 500 repetitions of this algorithm
+ * get more accurate the higher the value of iterations is Values from 0 up
+ * to 500 are allowed since double precision is not sufficient for more than
+ * about 500 repetitions of this algorithm
* @return the pi value of the calculation with a precision of x iteration
*/
public static double calculatePi(int iterations) {
diff --git a/src/main/java/com/thealgorithms/maths/PollardRho.java b/src/main/java/com/thealgorithms/maths/PollardRho.java
index 7fa913b21b7e..09d538587802 100644
--- a/src/main/java/com/thealgorithms/maths/PollardRho.java
+++ b/src/main/java/com/thealgorithms/maths/PollardRho.java
@@ -42,9 +42,9 @@ private PollardRho() {
/**
* This method returns a polynomial in x computed modulo n
*
- * @param base Integer base of the polynomial
+ * @param base Integer base of the polynomial
* @param modulus Integer is value which is to be used to perform modulo operation over the
- * polynomial
+ * polynomial
* @return Integer (((base * base) - 1) % modulus)
*/
static int g(int base, int modulus) {
diff --git a/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java b/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
index 93c8252ab929..24b9a36bcaa9 100644
--- a/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
+++ b/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java
@@ -2,6 +2,7 @@
/**
* calculate Power using Recursion
+ *
* @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
*/
diff --git a/src/main/java/com/thealgorithms/maths/PrimeCheck.java b/src/main/java/com/thealgorithms/maths/PrimeCheck.java
index 628a819aeba4..07a5e0da9360 100644
--- a/src/main/java/com/thealgorithms/maths/PrimeCheck.java
+++ b/src/main/java/com/thealgorithms/maths/PrimeCheck.java
@@ -69,10 +69,11 @@ public static boolean fermatPrimeChecking(int n, int iteration) {
/**
* *
+ *
* @param a basis
* @param b exponent
* @param c modulo
- * @return (a^b) mod c
+ * @return (a ^ b) mod c
*/
private static long modPow(long a, long b, long c) {
long res = 1;
diff --git a/src/main/java/com/thealgorithms/maths/ReverseNumber.java b/src/main/java/com/thealgorithms/maths/ReverseNumber.java
index 667a0a43fc2c..3409fe7e86ab 100644
--- a/src/main/java/com/thealgorithms/maths/ReverseNumber.java
+++ b/src/main/java/com/thealgorithms/maths/ReverseNumber.java
@@ -8,10 +8,10 @@ private ReverseNumber() {
}
/**
- * @brief reverses the input number
* @param number the input number
- * @exception IllegalArgumentException number is negative
* @return the number created by reversing the order of digits of the input number
+ * @throws IllegalArgumentException number is negative
+ * @brief reverses the input number
*/
public static int reverseNumber(int number) {
if (number < 0) {
diff --git a/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java b/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java
index 8f5d44dbe146..e2389ab64079 100644
--- a/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java
+++ b/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java
@@ -3,10 +3,10 @@
/**
* Translates numbers into the Roman Numeral System.
*
- * @see Roman
- * numerals
* @author Sokratis Fotkatzikis
* @version 1.0
+ * @see Roman
+ * numerals
*/
public final class RomanNumeralUtil {
private RomanNumeralUtil() {
diff --git a/src/main/java/com/thealgorithms/maths/SecondMinMax.java b/src/main/java/com/thealgorithms/maths/SecondMinMax.java
index e5a2d3b89085..43a9bac60978 100644
--- a/src/main/java/com/thealgorithms/maths/SecondMinMax.java
+++ b/src/main/java/com/thealgorithms/maths/SecondMinMax.java
@@ -6,8 +6,9 @@ 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
+ * @throws IllegalArgumentException => if input array is of length less than 2 also if all elements are same
* @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
*/
@@ -31,10 +32,10 @@ private static int secondBest(final int[] arr, final int initialVal, final BiPre
}
/**
- * @brief Finds the Second minimum / maximum value from the array
* @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
+ * @throws IllegalArgumentException => if input array is of length less than 2 also if all elements are same
+ * @brief Finds the Second minimum / maximum value from the array
* @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
*/
diff --git a/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java b/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
index f22d22e8c6af..9c0af07d3734 100644
--- a/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
+++ b/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java
@@ -50,10 +50,10 @@ private static int[] extractPrimes(Type[] isPrimeArray) {
}
/**
- * @brief finds all of the prime numbers up to the given upper (inclusive) limit
* @param n upper (inclusive) limit
- * @exception IllegalArgumentException n is non-positive
* @return the array of all primes up to the given number (inclusive)
+ * @throws IllegalArgumentException n is non-positive
+ * @brief finds all of the prime numbers up to the given upper (inclusive) limit
*/
public static int[] findPrimesTill(int n) {
return extractPrimes(sievePrimesTill(n));
diff --git a/src/main/java/com/thealgorithms/maths/SolovayStrassenPrimalityTest.java b/src/main/java/com/thealgorithms/maths/SolovayStrassenPrimalityTest.java
index caa1abfc3203..b815f7f775f1 100644
--- a/src/main/java/com/thealgorithms/maths/SolovayStrassenPrimalityTest.java
+++ b/src/main/java/com/thealgorithms/maths/SolovayStrassenPrimalityTest.java
@@ -6,7 +6,7 @@
* This class implements the Solovay-Strassen primality test,
* which is a probabilistic algorithm to determine whether a number is prime.
* The algorithm is based on properties of the Jacobi symbol and modular exponentiation.
- *
+ *
* For more information, go to {@link https://en.wikipedia.org/wiki/Solovay%E2%80%93Strassen_primality_test}
*/
final class SolovayStrassenPrimalityTest {
@@ -35,10 +35,10 @@ public static SolovayStrassenPrimalityTest getSolovayStrassenPrimalityTest(int s
/**
* Calculates modular exponentiation using the method of exponentiation by squaring.
*
- * @param base the base number
+ * @param base the base number
* @param exponent the exponent
- * @param mod the modulus
- * @return (base^exponent) mod mod
+ * @param mod the modulus
+ * @return (base ^ exponent) mod mod
*/
private static long calculateModularExponentiation(long base, long exponent, long mod) {
long x = 1; // This will hold the result of (base^exponent) % mod
@@ -60,7 +60,7 @@ private static long calculateModularExponentiation(long base, long exponent, lon
/**
* Computes the Jacobi symbol (a/n), which is a generalization of the Legendre symbol.
*
- * @param a the numerator
+ * @param a the numerator
* @param num the denominator (must be an odd positive integer)
* @return the Jacobi symbol value: 1, -1, or 0
*/
@@ -101,7 +101,7 @@ public int calculateJacobi(long a, long num) {
/**
* Performs the Solovay-Strassen primality test on a given number.
*
- * @param num the number to be tested for primality
+ * @param num the number to be tested for primality
* @param iterations the number of iterations to run for accuracy
* @return true if num is likely prime, false if it is composite
*/
diff --git a/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java b/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java
index 22e9fee00605..519397a62074 100644
--- a/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java
+++ b/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java
@@ -17,12 +17,13 @@
public final class SquareFreeInteger {
private SquareFreeInteger() {
}
+
/**
* This method returns whether an integer is square free
*
* @param number Integer value which is to be checked
* @return false when number has repeated prime factors
- * true when number has non repeated prime factors
+ * true when number has non repeated prime factors
* @throws IllegalArgumentException when number is negative or zero
*/
public static boolean isSquareFreeInteger(int number) {
diff --git a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
index 80d185c93785..f3a658c92106 100644
--- a/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
+++ b/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java
@@ -23,7 +23,7 @@ public static double squareRoot(int 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.
+ // 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);
}
diff --git a/src/main/java/com/thealgorithms/maths/StrobogrammaticNumber.java b/src/main/java/com/thealgorithms/maths/StrobogrammaticNumber.java
index bcd9a8467e50..77139b6becb4 100644
--- a/src/main/java/com/thealgorithms/maths/StrobogrammaticNumber.java
+++ b/src/main/java/com/thealgorithms/maths/StrobogrammaticNumber.java
@@ -12,6 +12,7 @@
public class StrobogrammaticNumber {
/**
* Check if a number is strobogrammatic
+ *
* @param number the number to be checked
* @return true if the number is strobogrammatic, false otherwise
*/
diff --git a/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java b/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
index 315f0d3a7d28..1301b0b5e7d6 100644
--- a/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
+++ b/src/main/java/com/thealgorithms/maths/SumOfArithmeticSeries.java
@@ -17,7 +17,7 @@ private SumOfArithmeticSeries() {
/**
* Calculate sum of arithmetic series
*
- * @param firstTerm the initial term of an arithmetic series
+ * @param firstTerm the initial term of an arithmetic series
* @param commonDiff the common difference of an arithmetic series
* @param numOfTerms the total terms of an arithmetic series
* @return sum of given arithmetic series
diff --git a/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java b/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
index c0a1e782659a..0b47575131dd 100644
--- a/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
+++ b/src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
@@ -2,7 +2,7 @@
/**
* This program calculates the sum of the first n odd numbers.
- *
+ *
* https://www.cuemath.com/algebra/sum-of-odd-numbers/
*/
diff --git a/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java b/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
index 5369182a0a94..7431e2a2b035 100644
--- a/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
+++ b/src/main/java/com/thealgorithms/maths/SumWithoutArithmeticOperators.java
@@ -5,10 +5,11 @@ 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
+ * 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
*/
public int getSum(int a, int b) {
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..6d508eb1e8e5 100644
--- a/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
+++ b/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
@@ -1,13 +1,11 @@
package com.thealgorithms.maths;
/**
+ * @author [Syed](https : / / github.com / roeticvampire)
* @file
- *
* @brief Calculates the [Cross
* Product](https://en.wikipedia.org/wiki/Cross_product) and the magnitude of
* two mathematical 3D vectors.
- *
- *
* @details Cross Product of two vectors gives a vector. Direction Ratios of a
* vector are the numeric parts of the given vector. They are the tree parts of
* the vector which determine the magnitude (value) of the vector. The method of
@@ -18,26 +16,24 @@
* 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
- *
- * @author [Syed](https://github.com/roeticvampire)
*/
public class VectorCrossProduct {
diff --git a/src/main/java/com/thealgorithms/maths/Volume.java b/src/main/java/com/thealgorithms/maths/Volume.java
index 0f282b2abae2..8d3feff872d4 100644
--- a/src/main/java/com/thealgorithms/maths/Volume.java
+++ b/src/main/java/com/thealgorithms/maths/Volume.java
@@ -72,8 +72,8 @@ public static double volumeCone(double radius, double height) {
/**
* Calculate the volume of a prism.
*
- * @param baseArea area of the given prism's base
- * @param height of given prism
+ * @param baseArea area of the given prism's base
+ * @param height of given prism
* @return volume of given prism
*/
public static double volumePrism(double baseArea, double height) {
@@ -83,8 +83,8 @@ public static double volumePrism(double baseArea, double height) {
/**
* Calculate the volume of a pyramid.
*
- * @param baseArea of the given pyramid's base
- * @param height of given pyramid
+ * @param baseArea of the given pyramid's base
+ * @param height of given pyramid
* @return volume of given pyramid
*/
public static double volumePyramid(double baseArea, double height) {
@@ -94,8 +94,8 @@ public static double volumePyramid(double baseArea, double height) {
/**
* Calculate the volume of a frustum of a cone.
*
- * @param r1 radius of the top of the frustum
- * @param r2 radius of the bottom of the frustum
+ * @param r1 radius of the top of the frustum
+ * @param r2 radius of the bottom of the frustum
* @param height height of the frustum
* @return volume of the frustum
*/
diff --git a/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java b/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java
index afd34933047a..b72a1ce137eb 100644
--- a/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java
+++ b/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java
@@ -5,7 +5,6 @@
/**
* @author Anirudh Buvanesh (https://github.com/anirudhb11) For more information
* see https://www.geeksforgeeks.org/matrix-exponentiation/
- *
*/
public final class Fibonacci {
private Fibonacci() {
@@ -50,7 +49,7 @@ private static int[][] matrixMultiplication(int[][] matrix1, int[][] matrix2) {
* Calculates the fibonacci number using matrix exponentiaition technique
*
* @param n The input n for which we have to determine the fibonacci number
- * Outputs the nth * fibonacci number
+ * Outputs the nth * fibonacci number
* @return a 2 X 1 array as { {F_n+1}, {F_n} }
*/
public static int[][] fib(int n) {
diff --git a/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java b/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java
index a7e3f651cc85..5b7cd77e9825 100644
--- a/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java
+++ b/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java
@@ -3,20 +3,20 @@
import java.awt.Color;
/**
+ * @author [Seth Falco](https://github.com/SethFalco)
* @brief A Java implementation of the official W3 documented procedure to
* calculate contrast ratio between colors on the web. This is used to calculate
* the readability of a foreground color on top of a background color.
- * @since 2020-10-15
* @see Color Contrast Ratio
- * @author [Seth Falco](https://github.com/SethFalco)
+ * @since 2020-10-15
*/
public class ColorContrastRatio {
/**
- * @brief Calculates the contrast ratio between two given colors.
* @param a Any color, used to get the red, green, and blue values.
* @param b Another color, which will be compared against the first color.
* @return The contrast ratio between the two colors.
+ * @brief Calculates the contrast ratio between two given colors.
*/
public double getContrastRatio(Color a, Color b) {
final double aColorLuminance = getRelativeLuminance(a);
@@ -30,9 +30,9 @@ public double getContrastRatio(Color a, Color b) {
}
/**
- * @brief Calculates the relative luminance of a given color.
* @param color Any color, used to get the red, green, and blue values.
* @return The relative luminance of the color.
+ * @brief Calculates the relative luminance of a given color.
* @see More info on relative luminance.
*/
public double getRelativeLuminance(Color color) {
@@ -44,9 +44,9 @@ public double getRelativeLuminance(Color color) {
}
/**
- * @brief Calculates the final value for a color to be used in the relative luminance formula as described in step 1.
* @param color8Bit 8-bit representation of a color component value.
* @return Value for the provided color component to be used in the relative luminance formula.
+ * @brief Calculates the final value for a color to be used in the relative luminance formula as described in step 1.
*/
public double getColor(int color8Bit) {
final double sRgb = getColorSRgb(color8Bit);
@@ -54,9 +54,9 @@ public double getColor(int color8Bit) {
}
/**
- * @brief Calculates the Color sRGB value as denoted in step 1 of the procedure document.
* @param color8Bit 8-bit representation of a color component value.
* @return A percentile value of the color component.
+ * @brief Calculates the Color sRGB value as denoted in step 1 of the procedure document.
*/
private double getColorSRgb(double color8Bit) {
return color8Bit / 255.0;
diff --git a/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java b/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java
index 706feab0c69d..8f939fe99b52 100644
--- a/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java
+++ b/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java
@@ -45,6 +45,7 @@ public static double[][] invert(double[][] a) {
}
return x;
}
+
/**
* Method to carry out the partial-pivoting Gaussian
* elimination. Here index[] stores pivoting order.
diff --git a/src/main/java/com/thealgorithms/misc/MapReduce.java b/src/main/java/com/thealgorithms/misc/MapReduce.java
index c076957344f9..854e8fc9488b 100644
--- a/src/main/java/com/thealgorithms/misc/MapReduce.java
+++ b/src/main/java/com/thealgorithms/misc/MapReduce.java
@@ -18,6 +18,7 @@
public final class MapReduce {
private MapReduce() {
}
+
/*
*Counting all the words frequency within a sentence.
*/
diff --git a/src/main/java/com/thealgorithms/misc/MatrixTranspose.java b/src/main/java/com/thealgorithms/misc/MatrixTranspose.java
index 743682780b01..ed6659298673 100644
--- a/src/main/java/com/thealgorithms/misc/MatrixTranspose.java
+++ b/src/main/java/com/thealgorithms/misc/MatrixTranspose.java
@@ -1,10 +1,8 @@
package com.thealgorithms.misc;
/**
- *
- *
*
Find the Transpose of Matrix!
- *
+ *
* Simply take input from the user and print the matrix before the transpose and
* after the transpose.
*
@@ -24,9 +22,9 @@ private MatrixTranspose() {
* Calculate the transpose of the given matrix.
*
* @param matrix The matrix to be transposed
+ * @return The transposed matrix
* @throws IllegalArgumentException if the matrix is empty
* @throws NullPointerException if the matrix is null
- * @return The transposed matrix
*/
public static int[][] transpose(int[][] matrix) {
if (matrix == null || matrix.length == 0) {
diff --git a/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java b/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java
index 89dfce3fe049..d5f9e3bc57cc 100644
--- a/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java
+++ b/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java
@@ -38,6 +38,7 @@ public static int[][] mirrorMatrix(final int[][] originalMatrix) {
}
return mirroredMatrix;
}
+
private static int[] reverseRow(final int[] inRow) {
int[] res = new int[inRow.length];
for (int i = 0; i < inRow.length; ++i) {
diff --git a/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java b/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
index 51dc099ba32e..90b98dd44990 100644
--- a/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/misc/PalindromeSinglyLinkedList.java
@@ -6,7 +6,7 @@
* 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/
*/
@@ -64,9 +64,11 @@ public static boolean isPalindromeOptimised(Node head) {
}
return true;
}
+
static class Node {
int val;
Node next;
+
Node(int val) {
this.val = val;
this.next = null;
diff --git a/src/main/java/com/thealgorithms/misc/TwoSumProblem.java b/src/main/java/com/thealgorithms/misc/TwoSumProblem.java
index 2fc4ed09a792..e1b42fb2797c 100644
--- a/src/main/java/com/thealgorithms/misc/TwoSumProblem.java
+++ b/src/main/java/com/thealgorithms/misc/TwoSumProblem.java
@@ -11,6 +11,7 @@ private TwoSumProblem() {
/**
* The function "twoSum" takes an array of integers and a target integer as input, and returns an
* array of two indices where the corresponding elements in the input array add up to the target.
+ *
* @param values An array of integers.
* @param target The target is the sum that we are trying to find using two numbers from the given array.
* @return A pair or indexes such that sum of values at these indexes equals to the target
diff --git a/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java b/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java
index b54cbec08f74..20bad20ea7fb 100644
--- a/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java
+++ b/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java
@@ -15,7 +15,7 @@ private ArrayLeftRotation() {
* Performs a left rotation on the given array by the specified number of positions.
*
* @param arr the array to be rotated
- * @param n the number of positions to rotate the array to the left
+ * @param n the number of positions to rotate the array to the left
* @return a new array containing the elements of the input array rotated to the left
*/
public static int[] rotateLeft(int[] arr, int n) {
diff --git a/src/main/java/com/thealgorithms/others/ArrayRightRotation.java b/src/main/java/com/thealgorithms/others/ArrayRightRotation.java
index 125edadb6e73..f731588d9a34 100644
--- a/src/main/java/com/thealgorithms/others/ArrayRightRotation.java
+++ b/src/main/java/com/thealgorithms/others/ArrayRightRotation.java
@@ -4,7 +4,7 @@
* Provides a method to perform a right rotation on an array.
* A left rotation operation shifts each element of the array
* by a specified number of positions to the right.
- *
+ *
* https://en.wikipedia.org/wiki/Right_rotation *
*/
public final class ArrayRightRotation {
@@ -15,7 +15,7 @@ private ArrayRightRotation() {
* Performs a right rotation on the given array by the specified number of positions.
*
* @param arr the array to be rotated
- * @param k the number of positions to rotate the array to the left
+ * @param k the number of positions to rotate the array to the left
* @return a new array containing the elements of the input array rotated to the left
*/
public static int[] rotateRight(int[] arr, int k) {
@@ -35,9 +35,10 @@ public static int[] rotateRight(int[] arr, int k) {
/**
* Performs reversing of a array
- * @param arr the array to be reversed
+ *
+ * @param arr the array to be reversed
* @param start starting position
- * @param end ending position
+ * @param end ending position
*/
private static void reverseArray(int[] arr, int start, int end) {
while (start < end) {
diff --git a/src/main/java/com/thealgorithms/others/BFPRT.java b/src/main/java/com/thealgorithms/others/BFPRT.java
index 58c6d4e56830..2160bbd35069 100644
--- a/src/main/java/com/thealgorithms/others/BFPRT.java
+++ b/src/main/java/com/thealgorithms/others/BFPRT.java
@@ -14,7 +14,7 @@ private BFPRT() {
* Returns the k smallest elements from the array using the BFPRT algorithm.
*
* @param arr the input array
- * @param k the number of smallest elements to return
+ * @param k the number of smallest elements to return
* @return an array containing the k smallest elements, or null if k is invalid
*/
public static int[] getMinKNumsByBFPRT(int[] arr, int k) {
@@ -39,7 +39,7 @@ public static int[] getMinKNumsByBFPRT(int[] arr, int k) {
* Returns the k-th smallest element from the array using the BFPRT algorithm.
*
* @param arr the input array
- * @param k the rank of the smallest element to find
+ * @param k the rank of the smallest element to find
* @return the k-th smallest element
*/
public static int getMinKthByBFPRT(int[] arr, int k) {
@@ -62,10 +62,10 @@ public static int[] copyArray(int[] arr) {
/**
* BFPRT recursive method to find the k-th smallest element.
*
- * @param arr the input array
+ * @param arr the input array
* @param begin the starting index
- * @param end the ending index
- * @param i the index of the desired smallest element
+ * @param end the ending index
+ * @param i the index of the desired smallest element
* @return the k-th smallest element
*/
public static int bfprt(int[] arr, int begin, int end, int i) {
@@ -86,9 +86,9 @@ public static int bfprt(int[] arr, int begin, int end, int i) {
/**
* Finds the median of medians as the pivot element.
*
- * @param arr the input array
+ * @param arr the input array
* @param begin the starting index
- * @param end the ending index
+ * @param end the ending index
* @return the median of medians
*/
public static int medianOfMedians(int[] arr, int begin, int end) {
@@ -104,10 +104,10 @@ public static int medianOfMedians(int[] arr, int begin, int end) {
/**
* Partitions the array around a pivot.
*
- * @param arr the input array
+ * @param arr the input array
* @param begin the starting index
- * @param end the ending index
- * @param num the pivot element
+ * @param end the ending index
+ * @param num the pivot element
* @return the range where the pivot is located
*/
public static int[] partition(int[] arr, int begin, int end, int num) {
@@ -129,9 +129,9 @@ public static int[] partition(int[] arr, int begin, int end, int num) {
/**
* Finds the median of the elements between the specified range.
*
- * @param arr the input array
+ * @param arr the input array
* @param begin the starting index
- * @param end the ending index
+ * @param end the ending index
* @return the median of the specified range
*/
public static int getMedian(int[] arr, int begin, int end) {
@@ -144,9 +144,9 @@ public static int getMedian(int[] arr, int begin, int end) {
/**
* Sorts a portion of the array using insertion sort.
*
- * @param arr the input array
+ * @param arr the input array
* @param begin the starting index
- * @param end the ending index
+ * @param end the ending index
*/
public static void insertionSort(int[] arr, int begin, int end) {
if (arr == null || arr.length < 2) {
@@ -167,8 +167,8 @@ public static void insertionSort(int[] arr, int begin, int end) {
* Swaps two elements in an array.
*
* @param arr the input array
- * @param i the index of the first element
- * @param j the index of the second element
+ * @param i the index of the first element
+ * @param j the index of the second element
*/
public static void swap(int[] arr, int i, int j) {
int temp = arr[i];
diff --git a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
index 836526529374..65ffaea401a8 100644
--- a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
+++ b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
@@ -5,16 +5,16 @@
/**
* This file contains an implementation of BANKER'S ALGORITM Wikipedia:
* https://en.wikipedia.org/wiki/Banker%27s_algorithm
- *
+ *
* 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.
*
@@ -38,16 +38,15 @@ static void calculateNeed(int[][] needArray, int[][] maxArray, int[][] allocatio
/**
* This method find the system is in safe state or not
*
- * @param processes[] int array of processes (0...n-1), size = n
- * @param availableArray[] int array of number of instances of each
- * resource, size = m
- * @param maxArray[][] int matrix(2-D array) of maximum demand of each
- * process in a system, size = n*m
+ * @param processes[] int array of processes (0...n-1), size = n
+ * @param availableArray[] int array of number of instances of each
+ * resource, size = m
+ * @param maxArray[][] int matrix(2-D array) of maximum demand of each
+ * process in a system, size = n*m
* @param allocationArray[][] int matrix(2-D array) of the number of
- * resources of each type currently allocated to each process, size = n*m
- * @param totalProcess number of total processes, n
- * @param totalResources number of total resources, m
- *
+ * resources of each type currently allocated to each process, size = n*m
+ * @param totalProcess number of total processes, n
+ * @param totalResources number of total resources, m
* @return boolean if the system is in safe state or not
*/
static boolean checkSafeSystem(int[] processes, int[] availableArray, int[][] maxArray, int[][] allocationArray, int totalProcess, int totalResources) {
diff --git a/src/main/java/com/thealgorithms/others/BoyerMoore.java b/src/main/java/com/thealgorithms/others/BoyerMoore.java
index 3fb97724b5ac..0be386bff740 100644
--- a/src/main/java/com/thealgorithms/others/BoyerMoore.java
+++ b/src/main/java/com/thealgorithms/others/BoyerMoore.java
@@ -1,11 +1,12 @@
package com.thealgorithms.others;
+
import java.util.Optional;
/**
* Utility class implementing Boyer-Moore's Voting Algorithm to find the majority element
* in an array. The majority element is defined as the element that appears more than n/2 times
* in the array, where n is the length of the array.
- *
+ *
* For more information on the algorithm, refer to:
* https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
*/
@@ -55,7 +56,7 @@ private static int findCandidate(final int[] array) {
* Counts the occurrences of the candidate element in the array.
*
* @param candidate the candidate element
- * @param array the input array
+ * @param array the input array
* @return the number of times the candidate appears in the array
*/
private static int countOccurrences(final int candidate, final int[] array) {
@@ -71,7 +72,7 @@ private static int countOccurrences(final int candidate, final int[] array) {
/**
* Determines if the count of the candidate element is more than n/2, where n is the length of the array.
*
- * @param count the number of occurrences of the candidate
+ * @param count the number of occurrences of the candidate
* @param totalCount the total number of elements in the array
* @return true if the candidate is the majority element, false otherwise
*/
diff --git a/src/main/java/com/thealgorithms/others/CRCAlgorithm.java b/src/main/java/com/thealgorithms/others/CRCAlgorithm.java
index 284a290a5af8..9be40642f37d 100644
--- a/src/main/java/com/thealgorithms/others/CRCAlgorithm.java
+++ b/src/main/java/com/thealgorithms/others/CRCAlgorithm.java
@@ -33,10 +33,10 @@ public class CRCAlgorithm {
* The algorithm's main constructor. The most significant variables, used in
* the algorithm, are set in their initial values.
*
- * @param str The binary number P, in a string form, which is used by the
- * CRC algorithm
+ * @param str The binary number P, in a string form, which is used by the
+ * CRC algorithm
* @param size The size of every transmitted message
- * @param ber The Bit Error Rate
+ * @param ber The Bit Error Rate
*/
public CRCAlgorithm(String str, int size, double ber) {
messageChanged = false;
@@ -124,7 +124,7 @@ public void generateRandomMess() {
* message.
*
* @param check the variable used to determine, if the message is going to
- * be checked from the receiver if true, it is checked otherwise, it is not
+ * be checked from the receiver if true, it is checked otherwise, it is not
*/
public void divideMessageWithP(boolean check) {
ArrayList x = new ArrayList<>();
diff --git a/src/main/java/com/thealgorithms/others/Damm.java b/src/main/java/com/thealgorithms/others/Damm.java
index 55a4c5b81a89..1bec5c06a73e 100644
--- a/src/main/java/com/thealgorithms/others/Damm.java
+++ b/src/main/java/com/thealgorithms/others/Damm.java
@@ -44,8 +44,8 @@ private Damm() {
* @param digits input to check
* @return true if check was successful, false otherwise
* @throws IllegalArgumentException if input parameter contains not only
- * digits
- * @throws NullPointerException if input is null
+ * digits
+ * @throws NullPointerException if input is null
*/
public static boolean dammCheck(String digits) {
checkInput(digits);
@@ -66,8 +66,8 @@ public static boolean dammCheck(String digits) {
* @param initialDigits initial value
* @return digits with the checksum in the last position
* @throws IllegalArgumentException if input parameter contains not only
- * digits
- * @throws NullPointerException if input is null
+ * digits
+ * @throws NullPointerException if input is null
*/
public static String addDammChecksum(String initialDigits) {
checkInput(initialDigits);
diff --git a/src/main/java/com/thealgorithms/others/Dijkstra.java b/src/main/java/com/thealgorithms/others/Dijkstra.java
index a379100a2f3b..d848b83756d9 100644
--- a/src/main/java/com/thealgorithms/others/Dijkstra.java
+++ b/src/main/java/com/thealgorithms/others/Dijkstra.java
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.NavigableSet;
import java.util.TreeSet;
+
/**
* Dijkstra's algorithm,is a graph search algorithm that solves the
* single-source shortest path problem for a graph with nonnegative edge path
@@ -205,7 +206,7 @@ private void dijkstra(final NavigableSet q) {
u = q.pollFirst();
if (u.dist == Integer.MAX_VALUE) {
break; // we can ignore u (and any other remaining vertices) since they are
- // unreachable
+ // unreachable
}
// look at distances to each neighbour
for (Map.Entry a : u.neighbours.entrySet()) {
diff --git a/src/main/java/com/thealgorithms/others/FibbonaciSeries.java b/src/main/java/com/thealgorithms/others/FibbonaciSeries.java
index a4815296e547..7feb830a98df 100644
--- a/src/main/java/com/thealgorithms/others/FibbonaciSeries.java
+++ b/src/main/java/com/thealgorithms/others/FibbonaciSeries.java
@@ -11,7 +11,7 @@
*
*
* Source for the explanation: https://en.wikipedia.org/wiki/Fibonacci_number
- *
+ *
* Problem Statement: print all Fibonacci numbers that are smaller than your
* given input N
*/
diff --git a/src/main/java/com/thealgorithms/others/KochSnowflake.java b/src/main/java/com/thealgorithms/others/KochSnowflake.java
index 46b8edb1f177..4d313dd18658 100644
--- a/src/main/java/com/thealgorithms/others/KochSnowflake.java
+++ b/src/main/java/com/thealgorithms/others/KochSnowflake.java
@@ -77,8 +77,8 @@ public static void main(String[] args) {
* increases exponentially.
*
* @param initialVectors The vectors composing the shape to which the
- * algorithm is applied.
- * @param steps The number of iterations.
+ * algorithm is applied.
+ * @param steps The number of iterations.
* @return The transformed vectors after the iteration-steps.
*/
public static ArrayList iterate(ArrayList initialVectors, int steps) {
@@ -94,7 +94,7 @@ public static ArrayList iterate(ArrayList initialVectors, int
* Method to render the Koch snowflake to a image.
*
* @param imageWidth The width of the rendered image.
- * @param steps The number of iterations.
+ * @param steps The number of iterations.
* @return The image of the rendered Koch snowflake.
*/
public static BufferedImage getKochSnowflake(int imageWidth, int steps) {
@@ -123,7 +123,7 @@ public static BufferedImage getKochSnowflake(int imageWidth, int steps) {
* constructed through a 60 degree rotation so it is bent outwards.
*
* @param vectors The vectors composing the shape to which the algorithm is
- * applied.
+ * applied.
* @return The transformed vectors after the iteration-step.
*/
private static ArrayList iterationStep(List vectors) {
@@ -145,8 +145,8 @@ private static ArrayList iterationStep(List vectors) {
/**
* Utility-method to render the Koch snowflake to an image.
*
- * @param vectors The vectors defining the edges to be rendered.
- * @param imageWidth The width of the rendered image.
+ * @param vectors The vectors defining the edges to be rendered.
+ * @param imageWidth The width of the rendered image.
* @param imageHeight The height of the rendered image.
* @return The image of the rendered edges.
*/
diff --git a/src/main/java/com/thealgorithms/others/LineSweep.java b/src/main/java/com/thealgorithms/others/LineSweep.java
index b7db964c98d0..412bc289960d 100644
--- a/src/main/java/com/thealgorithms/others/LineSweep.java
+++ b/src/main/java/com/thealgorithms/others/LineSweep.java
@@ -7,10 +7,10 @@
* The Line Sweep algorithm is used to solve range problems efficiently. It works by:
* 1. Sorting a list of ranges by their start values in non-decreasing order.
* 2. Sweeping through the number line (x-axis) while updating a count for each point based on the ranges.
- *
+ *
* An overlapping range is defined as:
* - (StartA <= EndB) AND (EndA >= StartB)
- *
+ *
* References:
* - https://en.wikipedia.org/wiki/Sweep_line_algorithm
* - https://en.wikipedia.org/wiki/De_Morgan%27s_laws
diff --git a/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java b/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java
index 36bcca3edc00..d1aaae01a3ae 100644
--- a/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java
+++ b/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java
@@ -21,8 +21,8 @@ public class LinearCongruentialGenerator {
*
* @param multiplier
* @param increment
- * @param modulo The maximum number that can be generated (exclusive). A
- * common value is 2^32.
+ * @param modulo The maximum number that can be generated (exclusive). A
+ * common value is 2^32.
*/
public LinearCongruentialGenerator(double multiplier, double increment, double modulo) {
this(System.currentTimeMillis(), multiplier, increment, modulo);
@@ -35,8 +35,8 @@ public LinearCongruentialGenerator(double multiplier, double increment, double m
* @param seed
* @param multiplier
* @param increment
- * @param modulo The maximum number that can be generated (exclusive). A
- * common value is 2^32.
+ * @param modulo The maximum number that can be generated (exclusive). A
+ * common value is 2^32.
*/
public LinearCongruentialGenerator(double seed, double multiplier, double increment, double modulo) {
this.previousValue = seed;
diff --git a/src/main/java/com/thealgorithms/others/LowestBasePalindrome.java b/src/main/java/com/thealgorithms/others/LowestBasePalindrome.java
index 76d1ed4aba1d..8091dcc1f12f 100644
--- a/src/main/java/com/thealgorithms/others/LowestBasePalindrome.java
+++ b/src/main/java/com/thealgorithms/others/LowestBasePalindrome.java
@@ -5,7 +5,7 @@
/**
* @brief Class for finding the lowest base in which a given integer is a palindrome.
- cf. https://oeis.org/A016026
+ * cf. https://oeis.org/A016026
*/
public final class LowestBasePalindrome {
private LowestBasePalindrome() {
@@ -39,9 +39,9 @@ private static void checkNumber(int number) {
* Computes the digits of a given number in a specified base.
*
* @param number the number to be converted
- * @param base the base to be used for the conversion
+ * @param base the base to be used for the conversion
* @return a list of digits representing the number in the given base, with the most
- * significant digit at the end of the list
+ * significant digit at the end of the list
* @throws IllegalArgumentException if the number is negative or the base is less than 2
*/
public static List computeDigitsInBase(int number, int base) {
@@ -76,7 +76,7 @@ public static boolean isPalindromic(List list) {
* Checks if the representation of a given number in a specified base is palindromic.
*
* @param number the number to be checked
- * @param base the base in which the number will be represented
+ * @param base the base in which the number will be represented
* @return {@code true} if the number is palindromic in the specified base, {@code false} otherwise
* @throws IllegalArgumentException if the number is negative or the base is less than 2
*/
diff --git a/src/main/java/com/thealgorithms/others/Luhn.java b/src/main/java/com/thealgorithms/others/Luhn.java
index 600128a7725b..9c1012f07719 100644
--- a/src/main/java/com/thealgorithms/others/Luhn.java
+++ b/src/main/java/com/thealgorithms/others/Luhn.java
@@ -71,7 +71,7 @@ public static void main(String[] args) {
System.out.println("Luhn algorithm usage examples:");
int[] validInput = {4, 5, 6, 1, 2, 6, 1, 2, 1, 2, 3, 4, 5, 4, 6, 7};
int[] invalidInput = {4, 5, 6, 1, 2, 6, 1, 2, 1, 2, 3, 4, 5, 4, 6, 4}; // typo in last
- // symbol
+ // symbol
checkAndPrint(validInput);
checkAndPrint(invalidInput);
@@ -94,6 +94,7 @@ private static void checkAndPrint(int[] input) {
Business usage example
========================
*/
+
/**
* Object representation of credit card.
*/
@@ -102,10 +103,10 @@ private record CreditCard(int[] digits) {
/**
* @param cardNumber string representation of credit card number - 16
- * digits. Can have spaces for digits separation
+ * digits. Can have spaces for digits separation
* @return credit card object
* @throws IllegalArgumentException if input string is not 16 digits or
- * if Luhn check was failed
+ * if Luhn check was failed
*/
public static CreditCard fromString(String cardNumber) {
Objects.requireNonNull(cardNumber);
diff --git a/src/main/java/com/thealgorithms/others/Mandelbrot.java b/src/main/java/com/thealgorithms/others/Mandelbrot.java
index 6d7588090ba8..ac94555fe373 100644
--- a/src/main/java/com/thealgorithms/others/Mandelbrot.java
+++ b/src/main/java/com/thealgorithms/others/Mandelbrot.java
@@ -63,12 +63,12 @@ public static void main(String[] args) {
* area of the Mandelbrot set is roughly between "-1.5 < x < 0.5" and "-1 <
* y < 1" in the figure-coordinates.
*
- * @param imageWidth The width of the rendered image.
- * @param imageHeight The height of the rendered image.
- * @param figureCenterX The x-coordinate of the center of the figure.
- * @param figureCenterY The y-coordinate of the center of the figure.
- * @param figureWidth The width of the figure.
- * @param maxStep Maximum number of steps to check for divergent behavior.
+ * @param imageWidth The width of the rendered image.
+ * @param imageHeight The height of the rendered image.
+ * @param figureCenterX The x-coordinate of the center of the figure.
+ * @param figureCenterY The y-coordinate of the center of the figure.
+ * @param figureWidth The width of the figure.
+ * @param maxStep Maximum number of steps to check for divergent behavior.
* @param useDistanceColorCoding Render in color or black and white.
* @return The image of the rendered Mandelbrot set.
*/
diff --git a/src/main/java/com/thealgorithms/others/MaximumSlidingWindow.java b/src/main/java/com/thealgorithms/others/MaximumSlidingWindow.java
index d0b2c2a0e56d..aac9fcdeca7a 100644
--- a/src/main/java/com/thealgorithms/others/MaximumSlidingWindow.java
+++ b/src/main/java/com/thealgorithms/others/MaximumSlidingWindow.java
@@ -5,11 +5,11 @@
/**
* Maximum Sliding Window Algorithm
- *
+ *
* This algorithm finds the maximum element in each sliding window of size k
* in a given array of integers. It uses a deque (double-ended queue) to
* efficiently keep track of potential maximum values in the current window.
- *
+ *
* Time Complexity: O(n), where n is the number of elements in the input array
* Space Complexity: O(k), where k is the size of the sliding window
*/
@@ -19,7 +19,7 @@ public class MaximumSlidingWindow {
/**
* Finds the maximum values in each sliding window of size k.
*
- * @param nums The input array of integers
+ * @param nums The input array of integers
* @param windowSize The size of the sliding window
* @return An array of integers representing the maximums in each window
*/
diff --git a/src/main/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthK.java b/src/main/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthK.java
index c05f1af4e327..9e3aa212e6bb 100644
--- a/src/main/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthK.java
+++ b/src/main/java/com/thealgorithms/others/MaximumSumOfDistinctSubarraysWithLengthK.java
@@ -5,7 +5,7 @@
/**
* References: https://en.wikipedia.org/wiki/Streaming_algorithm
- *
+ *
* This model involves computing the maximum sum of subarrays of a fixed size \( K \) from a stream of integers.
* As the stream progresses, elements from the end of the window are removed, and new elements from the stream are added.
*
@@ -18,9 +18,8 @@ private MaximumSumOfDistinctSubarraysWithLengthK() {
/**
* Finds the maximum sum of a subarray of size K consisting of distinct elements.
*
- * @param k The size of the subarray.
+ * @param k The size of the subarray.
* @param nums The array from which subarrays will be considered.
- *
* @return The maximum sum of any distinct-element subarray of size K. If no such subarray exists, returns 0.
*/
public static long maximumSubarraySum(int k, int... nums) {
diff --git a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
index 0924b8569942..53517a69507a 100644
--- a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
+++ b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
@@ -1,6 +1,7 @@
package com.thealgorithms.others;
import java.util.ArrayList;
+
/**
* @author Alexandros Lemonaris
*/
@@ -12,10 +13,11 @@ public abstract class MemoryManagementAlgorithms {
* Abstract method since it is implemented different for each algorithm.
* It should return an ArrayList of Integers, where the index is the process
* ID (zero-indexed) and the value is the block number (also zero-indexed).
- * @param sizeOfBlocks an int array that contains the sizes of the memory
- * blocks available.
+ *
+ * @param sizeOfBlocks an int array that contains the sizes of the memory
+ * blocks available.
* @param sizeOfProcesses: an int array that contains the sizes of the
- * processes we need memory blocks for.
+ * processes we need memory blocks for.
* @return the ArrayList filled with Integers repressenting the memory
* allocation that took place.
*/
@@ -61,7 +63,7 @@ private static int findMaxElement(int[] array) {
* Method to find the index of the memory block that is going to fit the
* given process based on the best fit algorithm.
*
- * @param blocks: the array with the available memory blocks.
+ * @param blocks: the array with the available memory blocks.
* @param process: the size of the process.
* @return the index of the block that fits, or -255 if no such block
* exists.
@@ -71,7 +73,7 @@ private static int findBestFit(int[] blockSizes, int processSize) {
// processSize.
int minDiff = findMaxElement(blockSizes);
int index = NO_ALLOCATION; // If there is no block that can fit the process, return
- // NO_ALLOCATION as the
+ // NO_ALLOCATION as the
// result.
for (int i = 0; i < blockSizes.length; i++) { // Find the most fitting memory block for the given process.
if (blockSizes[i] - processSize < minDiff && blockSizes[i] - processSize >= 0) {
@@ -87,10 +89,10 @@ private static int findBestFit(int[] blockSizes, int processSize) {
* It should return an ArrayList of Integers, where the index is the process
* ID (zero-indexed) and the value is the block number (also zero-indexed).
*
- * @param sizeOfBlocks: an int array that contains the sizes of the memory
- * blocks available.
+ * @param sizeOfBlocks: an int array that contains the sizes of the memory
+ * blocks available.
* @param sizeOfProcesses: an int array that contains the sizes of the
- * processes we need memory blocks for.
+ * processes we need memory blocks for.
* @return the ArrayList filled with Integers repressenting the memory
* allocation that took place.
*/
@@ -119,7 +121,7 @@ class WorstFitCPU extends MemoryManagementAlgorithms {
* Method to find the index of the memory block that is going to fit the
* given process based on the worst fit algorithm.
*
- * @param blocks: the array with the available memory blocks.
+ * @param blocks: the array with the available memory blocks.
* @param process: the size of the process.
* @return the index of the block that fits, or -255 if no such block
* exists.
@@ -145,10 +147,10 @@ private static int findWorstFit(int[] blockSizes, int processSize) {
* It should return an ArrayList of Integers, where the index is the process
* ID (zero-indexed) and the value is the block number (also zero-indexed).
*
- * @param sizeOfBlocks: an int array that contains the sizes of the memory
- * blocks available.
+ * @param sizeOfBlocks: an int array that contains the sizes of the memory
+ * blocks available.
* @param sizeOfProcesses: an int array that contains the sizes of the
- * processes we need memory blocks for.
+ * processes we need memory blocks for.
* @return the ArrayList filled with Integers repressenting the memory
* allocation that took place.
*/
@@ -177,7 +179,7 @@ class FirstFitCPU extends MemoryManagementAlgorithms {
* Method to find the index of the memory block that is going to fit the
* given process based on the first fit algorithm.
*
- * @param blocks: the array with the available memory blocks.
+ * @param blocks: the array with the available memory blocks.
* @param process: the size of the process.
* @return the index of the block that fits, or -255 if no such block
* exists.
@@ -197,10 +199,10 @@ private static int findFirstFit(int[] blockSizes, int processSize) {
* It should return an ArrayList of Integers, where the index is the process
* ID (zero-indexed) and the value is the block number (also zero-indexed).
*
- * @param sizeOfBlocks: an int array that contains the sizes of the memory
- * blocks available.
+ * @param sizeOfBlocks: an int array that contains the sizes of the memory
+ * blocks available.
* @param sizeOfProcesses: an int array that contains the sizes of the
- * processes we need memory blocks for.
+ * processes we need memory blocks for.
* @return the ArrayList filled with Integers repressenting the memory
* allocation that took place.
*/
@@ -233,7 +235,7 @@ class NextFit extends MemoryManagementAlgorithms {
* if the search is interrupted in between, the new search is carried out from the last
* location.
*
- * @param blocks: the array with the available memory blocks.
+ * @param blocks: the array with the available memory blocks.
* @param process: the size of the process.
* @return the index of the block that fits, or -255 if no such block
* exists.
@@ -258,10 +260,10 @@ private int findNextFit(int[] blockSizes, int processSize) {
* It should return an ArrayList of Integers, where the index is the process
* ID (zero-indexed) and the value is the block number (also zero-indexed).
*
- * @param sizeOfBlocks: an int array that contains the sizes of the memory
- * blocks available.
+ * @param sizeOfBlocks: an int array that contains the sizes of the memory
+ * blocks available.
* @param sizeOfProcesses: an int array that contains the sizes of the
- * processes we need memory blocks for.
+ * processes we need memory blocks for.
* @return the ArrayList filled with Integers repressenting the memory
* allocation that took place.
*/
diff --git a/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java b/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java
index cd2cd02ab908..49baf34550f3 100644
--- a/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java
+++ b/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java
@@ -6,7 +6,7 @@
/**
* MiniMax is an algorithm used int artificial intelligence and game theory for
* minimizing the possible loss for the worst case scenario.
- *
+ *
* See more (https://en.wikipedia.org/wiki/Minimax,
* https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-1-introduction/).
*
@@ -48,10 +48,10 @@ public static void main(String[] args) {
/**
* Returns the optimal score assuming that both players play their best.
*
- * @param depth Indicates how deep we are into the game tree.
+ * @param depth Indicates how deep we are into the game tree.
* @param isMaximizer True if it is maximizers turn; otherwise false.
- * @param index Index of the leaf node that is being evaluated.
- * @param verbose True to show each players choices.
+ * @param index Index of the leaf node that is being evaluated.
+ * @param verbose True to show each players choices.
* @return The optimal score for the player that made the first move.
*/
public int miniMax(int depth, boolean isMaximizer, int index, boolean verbose) {
@@ -89,7 +89,7 @@ public int miniMax(int depth, boolean isMaximizer, int index, boolean verbose) {
/**
* Returns an array of random numbers which lenght is a power of 2.
*
- * @param size The power of 2 that will determine the lenght of the array.
+ * @param size The power of 2 that will determine the lenght of the array.
* @param maxScore The maximum possible score.
* @return An array of random numbers.
*/
diff --git a/src/main/java/com/thealgorithms/others/PerlinNoise.java b/src/main/java/com/thealgorithms/others/PerlinNoise.java
index e6551ed6b9ee..1b255c8418e5 100644
--- a/src/main/java/com/thealgorithms/others/PerlinNoise.java
+++ b/src/main/java/com/thealgorithms/others/PerlinNoise.java
@@ -12,11 +12,11 @@ private PerlinNoise() {
}
/**
- * @param width width of noise array
- * @param height height of noise array
+ * @param width width of noise array
+ * @param height height of noise array
* @param octaveCount numbers of layers used for blending noise
* @param persistence value of impact each layer get while blending
- * @param seed used for randomizer
+ * @param seed used for randomizer
* @return float array containing calculated "Perlin-Noise" values
*/
static float[][] generatePerlinNoise(int width, int height, int octaveCount, float persistence, long seed) {
@@ -65,8 +65,8 @@ static float[][] generatePerlinNoise(int width, int height, int octaveCount, flo
}
/**
- * @param base base random float array
- * @param width width of noise array
+ * @param base base random float array
+ * @param width width of noise array
* @param height height of noise array
* @param octave current layer
* @return float array containing calculated "Perlin-Noise-Layer" values
@@ -105,10 +105,10 @@ static float[][] generatePerlinNoiseLayer(float[][] base, int width, int height,
}
/**
- * @param a value of point a
- * @param b value of point b
+ * @param a value of point a
+ * @param b value of point b
* @param alpha determine which value has more impact (closer to 0 -> a,
- * closer to 1 -> b)
+ * closer to 1 -> b)
* @return interpolated value
*/
static float interpolate(float a, float b, float alpha) {
diff --git a/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java b/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java
index de36673512a0..76155228bfc5 100644
--- a/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java
+++ b/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java
@@ -29,8 +29,8 @@ public static void reverse(Stack stack) {
/**
* Inserts an element at the bottom of the given stack.
*
- * @param stack the stack where the element will be inserted
- * @param element the element to be inserted at the bottom
+ * @param stack the stack where the element will be inserted
+ * @param element the element to be inserted at the bottom
*/
private static void insertAtBottom(Stack stack, int element) {
if (stack.isEmpty()) {
diff --git a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
index 6ad0ef024342..2c71163ab1dc 100644
--- a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
+++ b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
@@ -1,6 +1,7 @@
package com.thealgorithms.others;
import java.util.Scanner;
+
/**
* Given a matrix of size n x n We have to rotate this matrix by 90 Degree Here
* is the algorithm for this problem .
diff --git a/src/main/java/com/thealgorithms/others/TowerOfHanoi.java b/src/main/java/com/thealgorithms/others/TowerOfHanoi.java
index 7017ed03f843..3ffa9fb98d68 100644
--- a/src/main/java/com/thealgorithms/others/TowerOfHanoi.java
+++ b/src/main/java/com/thealgorithms/others/TowerOfHanoi.java
@@ -8,7 +8,7 @@
* 1. Only one disc can be moved at a time.
* 2. A disc can only be placed on top of a larger disc.
* 3. All discs must start on one pole and end on another.
- *
+ *
* This implementation recursively calculates the steps required to solve the puzzle and stores them
* in a provided list.
*
@@ -16,7 +16,7 @@
* For more information about the Tower of Hanoi, see
* Tower of Hanoi on Wikipedia.
*
- *
+ *
* The {@code shift} method takes the number of discs and the names of the poles,
* and appends the steps required to solve the puzzle to the provided list.
* Time Complexity: O(2^n) - Exponential time complexity due to the recursive nature of the problem.
diff --git a/src/main/java/com/thealgorithms/others/Verhoeff.java b/src/main/java/com/thealgorithms/others/Verhoeff.java
index 9088612aaa43..7687fd0b6c9d 100644
--- a/src/main/java/com/thealgorithms/others/Verhoeff.java
+++ b/src/main/java/com/thealgorithms/others/Verhoeff.java
@@ -89,8 +89,8 @@ private Verhoeff() {
* @param digits input to check
* @return true if check was successful, false otherwise
* @throws IllegalArgumentException if input parameter contains not only
- * digits
- * @throws NullPointerException if input is null
+ * digits
+ * @throws NullPointerException if input is null
*/
public static boolean verhoeffCheck(String digits) {
checkInput(digits);
@@ -114,8 +114,8 @@ public static boolean verhoeffCheck(String digits) {
* @param initialDigits initial value
* @return digits with the checksum in the last position
* @throws IllegalArgumentException if input parameter contains not only
- * digits
- * @throws NullPointerException if input is null
+ * digits
+ * @throws NullPointerException if input is null
*/
public static String addVerhoeffChecksum(String initialDigits) {
checkInput(initialDigits);
diff --git a/src/main/java/com/thealgorithms/scheduling/AgingScheduling.java b/src/main/java/com/thealgorithms/scheduling/AgingScheduling.java
index 1e5512be9edd..0241146f9694 100644
--- a/src/main/java/com/thealgorithms/scheduling/AgingScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/AgingScheduling.java
@@ -7,7 +7,7 @@
* AgingScheduling is an algorithm designed to prevent starvation
* by gradually increasing the priority of waiting tasks.
* The longer a process waits, the higher its priority becomes.
- *
+ *
* Use Case: Useful in systems with mixed workloads to avoid
* lower-priority tasks being starved by higher-priority tasks.
*
@@ -36,7 +36,7 @@ public AgingScheduling() {
/**
* Adds a task to the scheduler with a given priority.
*
- * @param name name of the task
+ * @param name name of the task
* @param priority priority of the task
*/
public void addTask(String name, int priority) {
diff --git a/src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java b/src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java
index 776fc59c0c4d..5c8c718685f3 100644
--- a/src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java
@@ -7,7 +7,7 @@
* FairShareScheduling allocates CPU resources equally among users or groups
* instead of individual tasks. Each group gets a proportional share,
* preventing resource hogging by a single user's processes.
- *
+ *
* Use Case: Multi-user systems where users submit multiple tasks simultaneously,
* such as cloud environments.
*
diff --git a/src/main/java/com/thealgorithms/scheduling/GangScheduling.java b/src/main/java/com/thealgorithms/scheduling/GangScheduling.java
index ac1ce8ddd6ae..b76b5b976623 100644
--- a/src/main/java/com/thealgorithms/scheduling/GangScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/GangScheduling.java
@@ -8,7 +8,7 @@
/**
* GangScheduling groups related tasks (gangs) to run simultaneously on multiple processors.
* All tasks in a gang are executed together or not at all.
- *
+ *
* Use Case: Parallel computing environments where multiple threads of a program
* need to run concurrently for optimal performance.
*
diff --git a/src/main/java/com/thealgorithms/scheduling/HighestResponseRatioNextScheduling.java b/src/main/java/com/thealgorithms/scheduling/HighestResponseRatioNextScheduling.java
index 8ed689698557..281bb33702ba 100644
--- a/src/main/java/com/thealgorithms/scheduling/HighestResponseRatioNextScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/HighestResponseRatioNextScheduling.java
@@ -13,7 +13,7 @@
*
* Response Ratio = (waiting time + burst time) / burst time
*
- *
+ *
* HRRN is designed to reduce the average waiting time and improve overall
* system performance by balancing between short and long processes,
* minimizing process starvation.
@@ -62,9 +62,9 @@ private static class Process {
* in the system from arrival to completion. It is the sum of the burst time
* and the waiting time.
*
- * @param processNames Array of process names.
- * @param arrivalTimes Array of arrival times corresponding to each process.
- * @param burstTimes Array of burst times for each process.
+ * @param processNames Array of process names.
+ * @param arrivalTimes Array of arrival times corresponding to each process.
+ * @param burstTimes Array of burst times for each process.
* @param noOfProcesses The number of processes.
* @return An array of Turn Around Times for each process.
*/
@@ -106,7 +106,7 @@ public static int[] calculateTurnAroundTime(final String[] processNames, final i
* Calculates the Waiting Time (WT) for each process.
*
* @param turnAroundTime The Turn Around Times for each process.
- * @param burstTimes The burst times for each process.
+ * @param burstTimes The burst times for each process.
* @return An array of Waiting Times for each process.
*/
public static int[] calculateWaitingTime(int[] turnAroundTime, int[] burstTimes) {
@@ -120,7 +120,7 @@ public static int[] calculateWaitingTime(int[] turnAroundTime, int[] burstTimes)
/**
* Finds the next process to be scheduled based on arrival times and the current time.
*
- * @param processes Array of Process objects.
+ * @param processes Array of Process objects.
* @param currentTime The current time in the scheduling process.
* @return The index of the next process to be scheduled, or PROCESS_NOT_FOUND if no process is ready.
*/
@@ -135,7 +135,7 @@ private static int findNextProcess(Process[] processes, int currentTime) {
* (waiting time + burst time) / burst time
* where waiting time = current time - arrival time
*
- * @param processes Array of Process objects.
+ * @param processes Array of Process objects.
* @param currentTime The current time in the scheduling process.
* @return The index of the process with the highest response ratio, or PROCESS_NOT_FOUND if no process is ready.
*/
diff --git a/src/main/java/com/thealgorithms/scheduling/JobSchedulingWithDeadline.java b/src/main/java/com/thealgorithms/scheduling/JobSchedulingWithDeadline.java
index 49638d39fc2a..603399e2ce1b 100644
--- a/src/main/java/com/thealgorithms/scheduling/JobSchedulingWithDeadline.java
+++ b/src/main/java/com/thealgorithms/scheduling/JobSchedulingWithDeadline.java
@@ -6,7 +6,7 @@
/**
* A class that implements a job scheduling algorithm to maximize profit
* while adhering to job deadlines and arrival times.
- *
+ *
* This class provides functionality to schedule jobs based on their profit,
* arrival time, and deadlines to ensure that the maximum number of jobs is completed
* within the given timeframe. It sorts the jobs in decreasing order of profit
@@ -18,7 +18,7 @@ private JobSchedulingWithDeadline() {
/**
* Represents a job with an ID, arrival time, deadline, and profit.
- *
+ *
* Each job has a unique identifier, an arrival time (when it becomes available for scheduling),
* a deadline by which it must be completed, and a profit associated with completing the job.
*/
@@ -31,10 +31,10 @@ static class Job {
/**
* Constructs a Job instance with the specified job ID, arrival time, deadline, and profit.
*
- * @param jobId Unique identifier for the job
+ * @param jobId Unique identifier for the job
* @param arrivalTime Time when the job becomes available for scheduling
- * @param deadline Deadline for completing the job
- * @param profit Profit earned upon completing the job
+ * @param deadline Deadline for completing the job
+ * @param profit Profit earned upon completing the job
*/
Job(int jobId, int arrivalTime, int deadline, int profit) {
this.jobId = jobId;
@@ -46,7 +46,7 @@ static class Job {
/**
* Schedules jobs to maximize profit while respecting their deadlines and arrival times.
- *
+ *
* This method sorts the jobs in descending order of profit and attempts
* to allocate them to time slots that are before or on their deadlines,
* provided they have arrived. The function returns an array where the first element
@@ -55,8 +55,8 @@ static class Job {
* @param jobs An array of Job objects, each representing a job with an ID, arrival time,
* deadline, and profit.
* @return An array of two integers: the first element is the count of jobs
- * that were successfully scheduled, and the second element is the
- * total profit earned from those jobs.
+ * that were successfully scheduled, and the second element is the
+ * total profit earned from those jobs.
*/
public static int[] jobSequencingWithDeadlines(Job[] jobs) {
Arrays.sort(jobs, Comparator.comparingInt(job -> - job.profit));
diff --git a/src/main/java/com/thealgorithms/scheduling/MultiAgentScheduling.java b/src/main/java/com/thealgorithms/scheduling/MultiAgentScheduling.java
index 113b1691dec1..5a19690bc908 100644
--- a/src/main/java/com/thealgorithms/scheduling/MultiAgentScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/MultiAgentScheduling.java
@@ -9,7 +9,7 @@
* MultiAgentScheduling assigns tasks to different autonomous agents
* who independently decide the execution order of their assigned tasks.
* The focus is on collaboration between agents to optimize the overall schedule.
- *
+ *
* Use Case: Distributed scheduling in decentralized systems like IoT networks.
*
* @author Hardvan
diff --git a/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java b/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
index 1d8e2c5160ff..46caf24191ce 100644
--- a/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
@@ -48,7 +48,7 @@ static class Process implements Comparable {
*
* @param other The other process to compare against
* @return A negative integer, zero, or a positive integer as this process
- * is less than, equal to, or greater than the specified process.
+ * is less than, equal to, or greater than the specified process.
*/
@Override
public int compareTo(Process other) {
diff --git a/src/main/java/com/thealgorithms/scheduling/ProportionalFairScheduling.java b/src/main/java/com/thealgorithms/scheduling/ProportionalFairScheduling.java
index fd78dc571819..5ac769923c31 100644
--- a/src/main/java/com/thealgorithms/scheduling/ProportionalFairScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/ProportionalFairScheduling.java
@@ -7,7 +7,7 @@
* ProportionalFairScheduling allocates resources to processes based on their
* proportional weight or importance. It aims to balance fairness with
* priority, ensuring that higher-weight processes receive a larger share of resources.
- *
+ *
* Use Case: Network bandwidth allocation in cellular networks (4G/5G),
* where devices receive a proportional share of bandwidth.
*
diff --git a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
index 6d105003e68f..1d2f6de5c7b2 100644
--- a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
@@ -16,14 +16,16 @@ public class SJFScheduling {
/**
* a simple constructor
+ *
* @param processes a list of processes the user wants to schedule
- * it also sorts the processes based on the time of their arrival
+ * it also sorts the processes based on the time of their arrival
*/
SJFScheduling(final ArrayList processes) {
this.processes = processes;
schedule = new ArrayList<>();
sortByArrivalTime();
}
+
protected void sortByArrivalTime() {
int size = processes.size();
int i;
@@ -84,9 +86,10 @@ public void scheduleProcesses() {
/**
* this function evaluates the shortest job of all the ready processes (based on a process
* burst time)
+ *
* @param readyProcesses an array list of ready processes
* @return returns the process' with the shortest burst time OR NULL if there are no ready
- * processes
+ * processes
*/
private ProcessDetails findShortestJob(List readyProcesses) {
if (readyProcesses.isEmpty()) {
diff --git a/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java b/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java
index 99214fff20c4..ee05a3851123 100644
--- a/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java
@@ -22,6 +22,7 @@ public class SRTFScheduling {
/**
* Constructor
+ *
* @param processes ArrayList of ProcessDetails given as input
*/
public SRTFScheduling(ArrayList processes) {
diff --git a/src/main/java/com/thealgorithms/scheduling/SelfAdjustingScheduling.java b/src/main/java/com/thealgorithms/scheduling/SelfAdjustingScheduling.java
index 15159a07d2d4..1885041c7150 100644
--- a/src/main/java/com/thealgorithms/scheduling/SelfAdjustingScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/SelfAdjustingScheduling.java
@@ -7,7 +7,7 @@
* their priority based on real-time feedback, such as wait time and CPU usage.
* Tasks that wait longer will automatically increase their priority,
* allowing for better responsiveness and fairness in task handling.
- *
+ *
* Use Case: Real-time systems that require dynamic prioritization
* of tasks to maintain system responsiveness and fairness.
*
diff --git a/src/main/java/com/thealgorithms/scheduling/SlackTimeScheduling.java b/src/main/java/com/thealgorithms/scheduling/SlackTimeScheduling.java
index bbfd36f0f660..273cf45e4780 100644
--- a/src/main/java/com/thealgorithms/scheduling/SlackTimeScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/SlackTimeScheduling.java
@@ -8,7 +8,7 @@
* SlackTimeScheduling is an algorithm that prioritizes tasks based on their
* slack time, which is defined as the difference between the task's deadline
* and the time required to execute it. Tasks with less slack time are prioritized.
- *
+ *
* Use Case: Real-time systems with hard deadlines, such as robotics or embedded systems.
*
* @author Hardvan
diff --git a/src/main/java/com/thealgorithms/scheduling/diskscheduling/LookScheduling.java b/src/main/java/com/thealgorithms/scheduling/diskscheduling/LookScheduling.java
index beba69b05eca..9e074e06e508 100644
--- a/src/main/java/com/thealgorithms/scheduling/diskscheduling/LookScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/diskscheduling/LookScheduling.java
@@ -15,6 +15,7 @@ public class LookScheduling {
private final int currentPosition;
private boolean movingUp;
private int farthestPosition;
+
public LookScheduling(int startPosition, boolean initialDirection, int maxTrack) {
this.currentPosition = startPosition;
this.movingUp = initialDirection;
diff --git a/src/main/java/com/thealgorithms/scheduling/diskscheduling/SSFScheduling.java b/src/main/java/com/thealgorithms/scheduling/diskscheduling/SSFScheduling.java
index 261c1a388393..727606c9100c 100644
--- a/src/main/java/com/thealgorithms/scheduling/diskscheduling/SSFScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/diskscheduling/SSFScheduling.java
@@ -5,16 +5,16 @@
import java.util.List;
/**
- *https://en.wikipedia.org/wiki/Shortest_seek_first
+ * https://en.wikipedia.org/wiki/Shortest_seek_first
* Shortest Seek First (SFF) Scheduling algorithm implementation.
* The SFF algorithm selects the next request to be serviced based on the shortest distance
* from the current position of the disk arm. It continuously evaluates all pending requests
* and chooses the one that requires the least amount of movement to service.
- *
+ *
* This approach minimizes the average seek time, making it efficient in terms of response
* time for individual requests. However, it may lead to starvation for requests located
* further away from the current position of the disk arm.
- *
+ *
* The SFF algorithm is particularly effective in systems where quick response time
* is crucial, as it ensures that the most accessible requests are prioritized for servicing.
*/
diff --git a/src/main/java/com/thealgorithms/scheduling/diskscheduling/ScanScheduling.java b/src/main/java/com/thealgorithms/scheduling/diskscheduling/ScanScheduling.java
index 2c4fa7844a12..c32708910930 100644
--- a/src/main/java/com/thealgorithms/scheduling/diskscheduling/ScanScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/diskscheduling/ScanScheduling.java
@@ -10,11 +10,11 @@
* The SCAN algorithm moves the disk arm towards one end of the disk, servicing all requests
* along the way until it reaches the end. Once it reaches the end, it reverses direction
* and services the requests on its way back.
- *
+ *
* This algorithm ensures that all requests are serviced in a fair manner,
* while minimizing the seek time for requests located close to the current position
* of the disk arm.
- *
+ *
* The SCAN algorithm is particularly useful in environments with a large number of
* disk requests, as it reduces the overall movement of the disk arm compared to
*/
diff --git a/src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java b/src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java
index aeddc591b32b..240059227749 100644
--- a/src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java
+++ b/src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java
@@ -10,6 +10,7 @@
* Inverted Index implementation with BM25 Scoring for movie search.
* This class supports adding movie documents and searching for terms
* within those documents using the BM25 algorithm.
+ *
* @author Prayas Kumar (https://github.com/prayas7102)
*/
@@ -22,11 +23,12 @@ class Movie {
/**
* Constructor for the Movie class.
- * @param docId Unique identifier for the movie.
- * @param name Name of the movie.
- * @param imdbRating IMDb rating of the movie.
+ *
+ * @param docId Unique identifier for the movie.
+ * @param name Name of the movie.
+ * @param imdbRating IMDb rating of the movie.
* @param releaseYear Release year of the movie.
- * @param content Content or description of the movie.
+ * @param content Content or description of the movie.
*/
Movie(int docId, String name, double imdbRating, int releaseYear, String content) {
this.docId = docId;
@@ -39,6 +41,7 @@ class Movie {
/**
* Get all the words from the movie's name and content.
* Converts the name and content to lowercase and splits on non-word characters.
+ *
* @return Array of words from the movie name and content.
*/
public String[] getWords() {
@@ -58,7 +61,8 @@ class SearchResult {
/**
* Constructor for SearchResult class.
- * @param docId Document ID (movie) for this search result.
+ *
+ * @param docId Document ID (movie) for this search result.
* @param relevanceScore The relevance score based on BM25 scoring.
*/
SearchResult(int docId, double relevanceScore) {
@@ -119,11 +123,12 @@ public final class BM25InvertedIndex {
/**
* Add a movie to the index.
- * @param docId Unique identifier for the movie.
- * @param name Name of the movie.
- * @param imdbRating IMDb rating of the movie.
+ *
+ * @param docId Unique identifier for the movie.
+ * @param name Name of the movie.
+ * @param imdbRating IMDb rating of the movie.
* @param releaseYear Release year of the movie.
- * @param content Content or description of the movie.
+ * @param content Content or description of the movie.
*/
public void addMovie(int docId, String name, double imdbRating, int releaseYear, String content) {
Movie movie = new Movie(docId, name, imdbRating, releaseYear, content);
@@ -159,6 +164,7 @@ public int getMoviesLength() {
/**
* Search for documents containing a term using BM25 scoring.
+ *
* @param term The search term.
* @return A list of search results sorted by relevance score.
*/
@@ -196,9 +202,10 @@ public List search(String term) {
/**
* Compute the BM25 score for a given term and document.
+ *
* @param termFrequency The frequency of the term in the document.
- * @param docLength The length of the document.
- * @param idf The inverse document frequency of the term.
+ * @param docLength The length of the document.
+ * @param idf The inverse document frequency of the term.
* @return The BM25 relevance score for the term in the document.
*/
private double computeBM25Score(int termFrequency, double docLength, double idf) {
@@ -210,6 +217,7 @@ private double computeBM25Score(int termFrequency, double docLength, double idf)
/**
* Compute the inverse document frequency (IDF) of a term.
* The IDF measures the importance of a term across the entire document set.
+ *
* @param docFrequency The number of documents that contain the term.
* @return The inverse document frequency (IDF) value.
*/
diff --git a/src/main/java/com/thealgorithms/searches/BinarySearch.java b/src/main/java/com/thealgorithms/searches/BinarySearch.java
index bedad1667f33..64959b5dce06 100644
--- a/src/main/java/com/thealgorithms/searches/BinarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/BinarySearch.java
@@ -19,12 +19,21 @@ class BinarySearch implements SearchAlgorithm {
/**
* @param array is an array where the element should be found
- * @param key is an element which should be found
- * @param is any comparable type
+ * @param key is an element which should be found
+ * @param is any comparable type
* @return index of the element
*/
@Override
public > int find(T[] array, T key) {
+ if (array == null) {
+ throw new NullPointerException("Input array cannot be null");
+ }
+ if (key == null) {
+ throw new NullPointerException("Key cannot be null");
+ }
+ if (array.length == 0) {
+ return -1; // Explicitly handle empty array
+ }
return search(array, key, 0, array.length - 1);
}
@@ -32,8 +41,8 @@ public > int find(T[] array, T key) {
* This method implements the Generic Binary Search
*
* @param array The array to make the binary search
- * @param key The number you are looking for
- * @param left The lower bound
+ * @param key The number you are looking for
+ * @param left The lower bound
* @param right The upper bound
* @return the location of the key
*/
diff --git a/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java b/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java
index aa938447b864..b26d742b1ff4 100644
--- a/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java
+++ b/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java
@@ -6,7 +6,7 @@
* The search is performed using a combination of binary search on rows and
* columns.
* The 2D array must be strictly sorted in both rows and columns.
- *
+ *
* The algorithm works by:
* 1. Performing a binary search on the middle column of the 2D array.
* 2. Depending on the value found, it eliminates rows above or below the middle
@@ -26,7 +26,7 @@ private BinarySearch2dArray() {
* @param arr The 2D array to search in.
* @param target The value to search for.
* @return An array containing the row and column indices of the target, or [-1,
- * -1] if the target is not found.
+ * -1] if the target is not found.
*/
static int[] binarySearch(int[][] arr, int target) {
int rowCount = arr.length;
@@ -101,7 +101,7 @@ else if (arr[midRow][midCol] < target) {
* @param colStart The starting column index for the search.
* @param colEnd The ending column index for the search.
* @return An array containing the row and column indices of the target, or [-1,
- * -1] if the target is not found.
+ * -1] if the target is not found.
*/
static int[] binarySearch(int[][] arr, int target, int row, int colStart, int colEnd) {
// Perform binary search within the specified column range.
diff --git a/src/main/java/com/thealgorithms/searches/BreadthFirstSearch.java b/src/main/java/com/thealgorithms/searches/BreadthFirstSearch.java
index 7ac9c7b01526..c00915fe6f6e 100644
--- a/src/main/java/com/thealgorithms/searches/BreadthFirstSearch.java
+++ b/src/main/java/com/thealgorithms/searches/BreadthFirstSearch.java
@@ -11,6 +11,7 @@
/**
* Breadth-First Search implementation for tree/graph traversal.
+ *
* @author caos321
* @co-author @manishraj27
* @see Breadth-first search
@@ -22,7 +23,7 @@ public class BreadthFirstSearch {
/**
* Performs a breadth-first search to find a node with the given value.
*
- * @param root The root node to start the search from
+ * @param root The root node to start the search from
* @param value The value to search for
* @return Optional containing the found node, or empty if not found
*/
diff --git a/src/main/java/com/thealgorithms/searches/ExponentalSearch.java b/src/main/java/com/thealgorithms/searches/ExponentalSearch.java
index 9187dcbc2f4b..f9ef6b73cff8 100644
--- a/src/main/java/com/thealgorithms/searches/ExponentalSearch.java
+++ b/src/main/java/com/thealgorithms/searches/ExponentalSearch.java
@@ -25,8 +25,8 @@ class ExponentialSearch implements SearchAlgorithm {
* Finds the index of the specified key in a sorted array using exponential search.
*
* @param array The sorted array to search.
- * @param key The element to search for.
- * @param The type of the elements in the array, which must be comparable.
+ * @param key The element to search for.
+ * @param The type of the elements in the array, which must be comparable.
* @return The index of the key if found, otherwise -1.
*/
@Override
diff --git a/src/main/java/com/thealgorithms/searches/FibonacciSearch.java b/src/main/java/com/thealgorithms/searches/FibonacciSearch.java
index 2124938bc258..dfb5b31608a1 100644
--- a/src/main/java/com/thealgorithms/searches/FibonacciSearch.java
+++ b/src/main/java/com/thealgorithms/searches/FibonacciSearch.java
@@ -21,10 +21,10 @@ public class FibonacciSearch implements SearchAlgorithm {
* Finds the index of the specified key in a sorted array using Fibonacci search.
*
* @param array The sorted array to search.
- * @param key The element to search for.
- * @param The type of the elements in the array, which must be comparable.
- * @throws IllegalArgumentException if the input array is not sorted or empty, or if the key is null.
+ * @param key The element to search for.
+ * @param The type of the elements in the array, which must be comparable.
* @return The index of the key if found, otherwise -1.
+ * @throws IllegalArgumentException if the input array is not sorted or empty, or if the key is null.
*/
@Override
public > int find(T[] array, T key) {
diff --git a/src/main/java/com/thealgorithms/searches/InterpolationSearch.java b/src/main/java/com/thealgorithms/searches/InterpolationSearch.java
index 3ac6be25bf53..1ac6c7f7e710 100644
--- a/src/main/java/com/thealgorithms/searches/InterpolationSearch.java
+++ b/src/main/java/com/thealgorithms/searches/InterpolationSearch.java
@@ -24,7 +24,7 @@ class InterpolationSearch {
* Finds the index of the specified key in a sorted array using interpolation search.
*
* @param array The sorted array to search.
- * @param key The value to search for.
+ * @param key The value to search for.
* @return The index of the key if found, otherwise -1.
*/
public int find(int[] array, int key) {
diff --git a/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java b/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java
index 05fab0534267..94e3060dc161 100644
--- a/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java
@@ -24,7 +24,7 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
* This method implements an iterative version of binary search algorithm
*
* @param array a sorted array
- * @param key the key to search in array
+ * @param key the key to search in array
* @return the index of key in the array or -1 if not found
*/
@Override
diff --git a/src/main/java/com/thealgorithms/searches/LinearSearchThread.java b/src/main/java/com/thealgorithms/searches/LinearSearchThread.java
index ba3cff915f5f..5998837768fa 100644
--- a/src/main/java/com/thealgorithms/searches/LinearSearchThread.java
+++ b/src/main/java/com/thealgorithms/searches/LinearSearchThread.java
@@ -37,10 +37,10 @@ class Searcher extends Thread {
/**
* Constructor to initialize the Searcher.
*
- * @param arr The array to search in
- * @param left The starting index of the segment
+ * @param arr The array to search in
+ * @param left The starting index of the segment
* @param right The ending index of the segment
- * @param x The number to search for
+ * @param x The number to search for
*/
Searcher(int[] arr, int left, int right, int x) {
this.arr = arr;
diff --git a/src/main/java/com/thealgorithms/searches/LowerBound.java b/src/main/java/com/thealgorithms/searches/LowerBound.java
index 5a1401edd3c2..37826f2b3504 100644
--- a/src/main/java/com/thealgorithms/searches/LowerBound.java
+++ b/src/main/java/com/thealgorithms/searches/LowerBound.java
@@ -24,8 +24,8 @@ class LowerBound implements SearchAlgorithm {
/**
* @param array is an array where the LowerBound value is to be found
- * @param key is an element for which the LowerBound is to be found
- * @param is any comparable type
+ * @param key is an element for which the LowerBound is to be found
+ * @param is any comparable type
* @return index of the LowerBound element
*/
@Override
@@ -37,8 +37,8 @@ public > int find(T[] array, T key) {
* This method implements the Generic Binary Search
*
* @param array The array to make the binary search
- * @param key The number you are looking for
- * @param left The lower bound
+ * @param key The number you are looking for
+ * @param left The lower bound
* @param right The upper bound
* @return the location of the key
*/
diff --git a/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java b/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java
index aa74398b708b..024acf28ed33 100644
--- a/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java
+++ b/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java
@@ -8,7 +8,7 @@
/**
* Monte Carlo Tree Search (MCTS) is a heuristic search algorithm used in
* decition taking problems especially games.
- *
+ *
* See more: https://en.wikipedia.org/wiki/Monte_Carlo_tree_search,
* https://www.baeldung.com/java-monte-carlo-tree-search
*/
@@ -85,7 +85,7 @@ public void addChildNodes(Node node, int childCount) {
/**
* Uses UCT to find a promising child node to be explored.
- *
+ *
* UCT: Upper Confidence bounds applied to Trees.
*
* @param rootNode Root node of the tree.
diff --git a/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java b/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java
index 495e2e41bc5b..444fb04b8a74 100644
--- a/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java
@@ -18,8 +18,8 @@ public class PerfectBinarySearch implements SearchAlgorithm {
/**
* @param array is an array where the element should be found
- * @param key is an element which should be found
- * @param is any comparable type
+ * @param key is an element which should be found
+ * @param is any comparable type
* @return index of the element
*/
@Override
diff --git a/src/main/java/com/thealgorithms/searches/RandomSearch.java b/src/main/java/com/thealgorithms/searches/RandomSearch.java
index 3417ff7ddb21..119d887cdf19 100644
--- a/src/main/java/com/thealgorithms/searches/RandomSearch.java
+++ b/src/main/java/com/thealgorithms/searches/RandomSearch.java
@@ -24,7 +24,7 @@ public class RandomSearch implements SearchAlgorithm {
* Finds the index of a given element using random search.
*
* @param array Array to search through
- * @param key Element to search for
+ * @param key Element to search for
* @return Index of the element if found, -1 otherwise
*/
@Override
diff --git a/src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java b/src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java
index 3b4b0b08377f..d71c5e6bc115 100644
--- a/src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java
@@ -5,10 +5,10 @@
/**
* The search is for any array which is sorted row and column-wise too. For ex :
* {{10, 20, 30, 40},
- * {15, 25, 35, 45},
- * {18, 28, 38, 48},
- * {21, 31, 41, 51}}
- *
+ * {15, 25, 35, 45},
+ * {18, 28, 38, 48},
+ * {21, 31, 41, 51}}
+ *
* This array is sorted in both row and column manner.
* In this two pointers are taken, the first points to the 0th row and the second one points to end
* column, and then the element corresponding to the pointers placed in the array is compared with
diff --git a/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java b/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java
index 192c4d26c735..7d2821825c8d 100644
--- a/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java
+++ b/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java
@@ -25,9 +25,9 @@ private SaddlebackSearch() {
* @param row the current row.
* @param col the current column.
* @param key the element that we want to search for.
- * @throws IllegalArgumentException if the array is empty.
* @return The index(row and column) of the element if found. Else returns
* -1 -1.
+ * @throws IllegalArgumentException if the array is empty.
*/
static int[] find(int[][] arr, int row, int col, int key) {
if (arr.length == 0) {
diff --git a/src/main/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearch.java b/src/main/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearch.java
index 6a2a46c2821f..6397f3fec7f8 100644
--- a/src/main/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/SortOrderAgnosticBinarySearch.java
@@ -1,7 +1,9 @@
package com.thealgorithms.searches;
+
public final class SortOrderAgnosticBinarySearch {
private SortOrderAgnosticBinarySearch() {
}
+
public static int find(int[] arr, int key) {
int start = 0;
int end = arr.length - 1;
diff --git a/src/main/java/com/thealgorithms/searches/TernarySearch.java b/src/main/java/com/thealgorithms/searches/TernarySearch.java
index 4d9f55ea9917..71691f574e26 100644
--- a/src/main/java/com/thealgorithms/searches/TernarySearch.java
+++ b/src/main/java/com/thealgorithms/searches/TernarySearch.java
@@ -20,7 +20,7 @@
public class TernarySearch implements SearchAlgorithm {
/**
- * @param arr The **Sorted** array in which we will search the element.
+ * @param arr The **Sorted** array in which we will search the element.
* @param value The value that we want to search for.
* @return The index of the element if found. Else returns -1.
*/
@@ -30,10 +30,10 @@ public > int find(T[] arr, T value) {
}
/**
- * @param arr The **Sorted** array in which we will search the element.
- * @param key The value that we want to search for.
+ * @param arr The **Sorted** array in which we will search the element.
+ * @param key The value that we want to search for.
* @param start The starting index from which we will start Searching.
- * @param end The ending index till which we will Search.
+ * @param end The ending index till which we will Search.
* @return Returns the index of the Element if found. Else returns -1.
*/
private > int ternarySearch(T[] arr, T key, int start, int end) {
diff --git a/src/main/java/com/thealgorithms/searches/UnionFind.java b/src/main/java/com/thealgorithms/searches/UnionFind.java
index 01202a982266..47bd607d08c9 100644
--- a/src/main/java/com/thealgorithms/searches/UnionFind.java
+++ b/src/main/java/com/thealgorithms/searches/UnionFind.java
@@ -8,10 +8,10 @@
* The Union-Find data structure, also known as Disjoint Set Union (DSU),
* is a data structure that tracks a set of elements partitioned into
* disjoint (non-overlapping) subsets. It supports two main operations:
- *
+ *
* 1. **Find**: Determine which subset a particular element is in.
* 2. **Union**: Join two subsets into a single subset.
- *
+ *
* This implementation uses path compression in the `find` operation
* and union by rank in the `union` operation for efficiency.
*/
diff --git a/src/main/java/com/thealgorithms/searches/UpperBound.java b/src/main/java/com/thealgorithms/searches/UpperBound.java
index ec52c7a0ae5c..04ce3b6fd7b9 100644
--- a/src/main/java/com/thealgorithms/searches/UpperBound.java
+++ b/src/main/java/com/thealgorithms/searches/UpperBound.java
@@ -24,8 +24,8 @@ class UpperBound implements SearchAlgorithm {
/**
* @param array is an array where the UpperBound value is to be found
- * @param key is an element for which the UpperBound is to be found
- * @param is any comparable type
+ * @param key is an element for which the UpperBound is to be found
+ * @param is any comparable type
* @return index of the UpperBound element
*/
@Override
@@ -37,8 +37,8 @@ public > int find(T[] array, T key) {
* This method implements the Generic Binary Search
*
* @param array The array to make the binary search
- * @param key The number you are looking for
- * @param left The lower bound
+ * @param key The number you are looking for
+ * @param left The lower bound
* @param right The upper bound
* @return the location of the key
*/
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/ConstrainedShuffle.java b/src/main/java/com/thealgorithms/shufflealogrithm/ConstrainedShuffle.java
new file mode 100644
index 000000000000..7cb22c2ca468
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/ConstrainedShuffle.java
@@ -0,0 +1,44 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.Arrays;
+import java.util.Random;
+
+public final class ConstrainedShuffle {
+
+ private ConstrainedShuffle() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Shuffles elements in the array while ensuring that the first and last
+ * elements remain fixed.
+ *
+ * @param array the input array to shuffle
+ */
+ public static void constrainedShuffle(int[] array) {
+ // Edge case: If the array has less than 3 elements, no shuffling can occur
+ if (array == null || array.length < 3) {
+ return;
+ }
+
+ Random random = new Random();
+ // Start loop from the second last element and exclude the first and last
+ // elements
+ for (int i = array.length - 2; i > 1; i--) {
+ // Generate a random index between 1 and i (inclusive)
+ int j = random.nextInt(i - 1) + 1;
+
+ // Swap the elements at positions i and j
+ int temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ }
+
+ public static void main(String[] args) {
+ int[] array = {1, 2, 3, 4, 5};
+ System.out.println("Original Array: " + Arrays.toString(array));
+ constrainedShuffle(array);
+ System.out.println("Constrained Shuffled Array: " + Arrays.toString(array));
+ }
+}
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/GroupShuffle.java b/src/main/java/com/thealgorithms/shufflealogrithm/GroupShuffle.java
new file mode 100644
index 000000000000..b9062ff7254b
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/GroupShuffle.java
@@ -0,0 +1,53 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public final class GroupShuffle {
+
+ private GroupShuffle() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Groups and shuffles elements in the array.
+ *
+ * @param array the input array to shuffle
+ * @param groupSize the size of each group
+ * @return a list of shuffled groups
+ */
+ public static List> groupShuffle(int[] array, int groupSize) {
+ List> groups = new ArrayList<>();
+
+ // Edge case: Check if the group size is valid
+ if (array == null || groupSize <= 0) {
+ return groups;
+ }
+
+ for (int i = 0; i < array.length; i += groupSize) {
+ List group = new ArrayList<>();
+ for (int j = i; j < Math.min(i + groupSize, array.length); j++) {
+ group.add(array[j]);
+ }
+ groups.add(group);
+ }
+
+ // Shuffle only if the group size is greater than 1
+ if (groupSize > 1) {
+ Collections.shuffle(groups);
+ }
+
+ return groups;
+ }
+
+ public static void main(String[] args) {
+ int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+ List> shuffledGroups = groupShuffle(array, 3);
+
+ System.out.println("Shuffled Groups:");
+ for (List group : shuffledGroups) {
+ System.out.println(group);
+ }
+ }
+}
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/ShuffleByRange.java b/src/main/java/com/thealgorithms/shufflealogrithm/ShuffleByRange.java
new file mode 100644
index 000000000000..48ebf2480ed8
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/ShuffleByRange.java
@@ -0,0 +1,48 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.Random;
+
+public final class ShuffleByRange {
+
+ private ShuffleByRange() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Shuffles elements in the specified range of the array.
+ *
+ * @param array the input array to shuffle
+ * @param start the starting index of the range (inclusive)
+ * @param end the ending index of the range (exclusive)
+ */
+ public static void shuffleByRange(int[] array, int start, int end) {
+ // Edge case: Check if the range is valid
+ if (array == null || start < 0 || end > array.length || start >= end) {
+ return;
+ }
+
+ Random random = new Random();
+ for (int i = end - 1; i > start; i--) {
+ int j = random.nextInt(i - start + 1) + start;
+
+ // Swap the elements at positions i and j
+ int temp = array[i]; // Temporarily store the element at i
+ array[i] = array[j]; // Move element from j to i
+ array[j] = temp; // Place the stored element in position j
+ }
+ }
+
+ public static void main(String[] args) {
+ int[] array = {1, 2, 3, 4, 5, 6};
+ System.out.println("Original Array: ");
+ for (int num : array) {
+ System.out.print(num + " ");
+ }
+
+ shuffleByRange(array, 1, 5);
+ System.out.println("\nShuffled Array (Range 1 to 5): ");
+ for (int num : array) {
+ System.out.print(num + " ");
+ }
+ }
+}
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/UnderstandingShuffleAlgo.java b/src/main/java/com/thealgorithms/shufflealogrithm/UnderstandingShuffleAlgo.java
new file mode 100644
index 000000000000..9b6d6632828e
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/UnderstandingShuffleAlgo.java
@@ -0,0 +1,59 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.Random;
+
+public final class UnderstandingShuffleAlgo {
+
+ private UnderstandingShuffleAlgo() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Shuffles the elements in the array randomly.
+ * Uses a method that gives each item an equal chance to appear in any
+ * position.
+ *
+ * @param array the array to be shuffled
+ */
+ public static void shuffle(int[] array) {
+ // Create a Random object to generate random numbers
+ Random random = new Random();
+
+ // Loop from the last element to the second element
+ for (int i = array.length - 1; i > 0; i--) {
+ // Generate a random index from 0 to i (inclusive)
+ int j = random.nextInt(i + 1);
+
+ // Swap the elements at positions i and j
+ int temp = array[i]; // Temporarily store the element at i
+ array[i] = array[j]; // Move element from j to i
+ array[j] = temp; // Place the stored element in position j
+ }
+ }
+
+ /**
+ * Main method to demonstrate the shuffle function.
+ * Shows the array before and after shuffling.
+ *
+ * @param args command-line arguments (not used here)
+ */
+ public static void main(String[] args) {
+ // Create an example array of numbers from 1 to 9
+ int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+ // Display the original array
+ System.out.println("Original Array:");
+ for (int num : array) {
+ System.out.print(num + " ");
+ }
+
+ // Call the shuffle method to randomize the array
+ shuffle(array);
+
+ // Display the shuffled array
+ System.out.println("\nShuffled Array:");
+ for (int num : array) {
+ System.out.print(num + " ");
+ }
+ }
+}
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/UniquePairShuffle.java b/src/main/java/com/thealgorithms/shufflealogrithm/UniquePairShuffle.java
new file mode 100644
index 000000000000..b958cc9e8079
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/UniquePairShuffle.java
@@ -0,0 +1,55 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public final class UniquePairShuffle {
+
+ private UniquePairShuffle() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Pairs each element in the array with another element randomly, ensuring no
+ * pair repeats. If the array length is odd, pairing cannot be completed, so
+ * an empty list is returned.
+ *
+ * @param array the input array to pair elements from
+ * @return a list of unique pairs where each pair is represented as an integer
+ * array of length 2
+ */
+ public static List pairShuffle(int[] array) {
+ List pairs = new ArrayList<>();
+
+ // Handle edge case: If the array length is odd, pairing is not possible
+ if (array.length < 2 || array.length % 2 != 0) {
+ return pairs;
+ }
+
+ List shuffledList = new ArrayList<>();
+ for (int num : array) {
+ shuffledList.add(num);
+ }
+
+ // Shuffle elements to create random pairs
+ Collections.shuffle(shuffledList);
+
+ // Form pairs from the shuffled elements
+ for (int i = 0; i < shuffledList.size(); i += 2) {
+ pairs.add(new int[] {shuffledList.get(i), shuffledList.get(i + 1)});
+ }
+
+ return pairs;
+ }
+
+ public static void main(String[] args) {
+ int[] array = {1, 2, 3, 4};
+ List pairs = pairShuffle(array);
+
+ System.out.println("Generated Unique Pairs:");
+ for (int[] pair : pairs) {
+ System.out.println(pair[0] + " - " + pair[1]);
+ }
+ }
+}
diff --git a/src/main/java/com/thealgorithms/shufflealogrithm/WeightedShuffle.java b/src/main/java/com/thealgorithms/shufflealogrithm/WeightedShuffle.java
new file mode 100644
index 000000000000..acbb9c52bc29
--- /dev/null
+++ b/src/main/java/com/thealgorithms/shufflealogrithm/WeightedShuffle.java
@@ -0,0 +1,54 @@
+package com.thealgorithms.shufflealogrithm;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Random;
+
+public final class WeightedShuffle {
+
+ private WeightedShuffle() {
+ // Prevent instantiation
+ }
+
+ /**
+ * Shuffles elements based on their weights. Higher weight elements are more
+ * likely to appear earlier.
+ *
+ * @param array the input array to shuffle
+ * @param weights the weights for each corresponding element in the array
+ */
+ public static void weightedShuffle(int[] array, int[] weights) {
+ // Edge case: Check if weights match the array size
+ if (array == null || weights == null || array.length != weights.length) {
+ return;
+ }
+
+ Integer[] indices = new Integer[array.length];
+ for (int i = 0; i < array.length; i++) {
+ indices[i] = i;
+ }
+
+ Random random = new Random();
+
+ // Sort indices by weights in descending order, prioritizing higher weights
+ Arrays.sort(indices, Comparator.comparingInt((Integer i) -> - weights[i]).thenComparingInt(i -> random.nextInt()));
+
+ int[] result = new int[array.length];
+ for (int i = 0; i < array.length; i++) {
+ result[i] = array[indices[i]];
+ }
+
+ System.arraycopy(result, 0, array, 0, array.length);
+ }
+
+ public static void main(String[] args) {
+ int[] array = {10, 20, 30};
+ int[] weights = {1, 3, 2};
+ weightedShuffle(array, weights);
+
+ System.out.println("Weighted Shuffled Array:");
+ for (int num : array) {
+ System.out.print(num + " ");
+ }
+ }
+}
diff --git a/src/main/java/com/thealgorithms/slidingwindow/LongestSubstringWithoutRepeatingCharacters.java b/src/main/java/com/thealgorithms/slidingwindow/LongestSubstringWithoutRepeatingCharacters.java
index 0641730d8b09..f5fd3797cd66 100644
--- a/src/main/java/com/thealgorithms/slidingwindow/LongestSubstringWithoutRepeatingCharacters.java
+++ b/src/main/java/com/thealgorithms/slidingwindow/LongestSubstringWithoutRepeatingCharacters.java
@@ -1,4 +1,5 @@
package com.thealgorithms.slidingwindow;
+
import java.util.HashSet;
/**
@@ -12,7 +13,7 @@
* Worst-case space complexity O(min(n, m)), where n is the length of the string
* and m is the size of the character set.
*
- * @author (https://github.com/Chiefpatwal)
+ * @author (https : / / github.com / Chiefpatwal)
*/
public final class LongestSubstringWithoutRepeatingCharacters {
diff --git a/src/main/java/com/thealgorithms/slidingwindow/MinSumKSizeSubarray.java b/src/main/java/com/thealgorithms/slidingwindow/MinSumKSizeSubarray.java
index 40a5441fa7a0..f31ffb272d17 100644
--- a/src/main/java/com/thealgorithms/slidingwindow/MinSumKSizeSubarray.java
+++ b/src/main/java/com/thealgorithms/slidingwindow/MinSumKSizeSubarray.java
@@ -1,4 +1,5 @@
package com.thealgorithms.slidingwindow;
+
/**
* The Sliding Window algorithm is used to find the minimum sum of a subarray
* of a fixed size k within a given array.
@@ -8,7 +9,7 @@
* Best-case performance O(n)
* Average performance O(n)
* Worst-case space complexity O(1)
- *
+ *
* This class provides a static method to find the minimum sum of a subarray
* with a specified length k.
*
diff --git a/src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java b/src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java
index b6f5d92e7928..984553a986bc 100644
--- a/src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java
+++ b/src/main/java/com/thealgorithms/sorts/BinaryInsertionSort.java
@@ -10,7 +10,7 @@ public class BinaryInsertionSort implements SortAlgorithm {
/**
* Sorts the given array using the Binary Insertion Sort algorithm.
*
- * @param the type of elements in the array, which must implement the Comparable interface
+ * @param the type of elements in the array, which must implement the Comparable interface
* @param array the array to be sorted
* @return the sorted array
*/
diff --git a/src/main/java/com/thealgorithms/sorts/BitonicSort.java b/src/main/java/com/thealgorithms/sorts/BitonicSort.java
index 90d204818729..d596652cda8c 100644
--- a/src/main/java/com/thealgorithms/sorts/BitonicSort.java
+++ b/src/main/java/com/thealgorithms/sorts/BitonicSort.java
@@ -15,7 +15,7 @@ private enum Direction {
/**
* Sorts the given array using the Bitonic Sort algorithm.
*
- * @param the type of elements in the array, which must implement the Comparable interface
+ * @param the type of elements in the array, which must implement the Comparable interface
* @param array the array to be sorted
* @return the sorted array
*/
@@ -54,10 +54,10 @@ private > void bitonicSort(final T[] array, final int lo
/**
* Merges the bitonic sequence in the specified direction.
*
- * @param the type of elements in the array, which must be Comparable
- * @param array the array containing the bitonic sequence to be merged
- * @param low the starting index of the sequence to be merged
- * @param cnt the number of elements in the sequence to be merged
+ * @param the type of elements in the array, which must be Comparable
+ * @param array the array containing the bitonic sequence to be merged
+ * @param low the starting index of the sequence to be merged
+ * @param cnt the number of elements in the sequence to be merged
* @param direction the direction of sorting
*/
private > void bitonicMerge(T[] array, int low, int cnt, Direction direction) {
@@ -101,7 +101,7 @@ private static int nextPowerOfTwo(int n) {
/**
* Finds the maximum element in the given array.
*
- * @param the type of elements in the array, which must implement the Comparable interface
+ * @param the type of elements in the array, which must implement the Comparable interface
* @param array the array to be searched
* @return the maximum element in the array
* @throws IllegalArgumentException if the array is null or empty
diff --git a/src/main/java/com/thealgorithms/sorts/BubbleSort.java b/src/main/java/com/thealgorithms/sorts/BubbleSort.java
index 6823c68d0a74..5fb85109581a 100644
--- a/src/main/java/com/thealgorithms/sorts/BubbleSort.java
+++ b/src/main/java/com/thealgorithms/sorts/BubbleSort.java
@@ -11,7 +11,7 @@ class BubbleSort implements SortAlgorithm {
* Implements generic bubble sort algorithm.
*
* @param array the array to be sorted.
- * @param the type of elements in the array.
+ * @param the type of elements in the array.
* @return the sorted array.
*/
@Override
diff --git a/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java b/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java
index d9cc00f95b69..43787884f1b4 100644
--- a/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java
+++ b/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java
@@ -18,7 +18,7 @@ public