From 77fd16f4f5c07974aa9de10f88aaaf8123ae0d9c Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Fri, 8 Sep 2023 16:03:47 +0530 Subject: [PATCH 1/4] Fixed Small typos :-) --- src/main/java/com/thealgorithms/io/BufferedReader.java | 6 +++--- src/main/java/com/thealgorithms/maths/AmicableNumber.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/thealgorithms/io/BufferedReader.java b/src/main/java/com/thealgorithms/io/BufferedReader.java index 7909eaa96eae..9b47148976c4 100644 --- a/src/main/java/com/thealgorithms/io/BufferedReader.java +++ b/src/main/java/com/thealgorithms/io/BufferedReader.java @@ -16,7 +16,7 @@ public class BufferedReader { private static final int DEFAULT_BUFFER_SIZE = 5; /** - * Maximum number of bytes the buffer can hold. + * The Maximum number of bytes the buffer can hold. * Value is changed when encountered Eof to not * cause overflow read of 0 bytes */ @@ -100,7 +100,7 @@ public int peek(int n) throws IOException { * Removes the already read bytes from the buffer * in-order to make space for new bytes to be filled up. *

- * This may also do the job to read first time data (whole buffer is empty) + * This may also do the job to read first time data (the whole buffer is empty) */ private void pushRefreshData() throws IOException { @@ -116,7 +116,7 @@ private void pushRefreshData() throws IOException { /** * Reads one complete block of size {bufferSize} - * if found eof, the total length of array will + * if found eof, the total length of an array will * be that of what's available * * @return a completed block diff --git a/src/main/java/com/thealgorithms/maths/AmicableNumber.java b/src/main/java/com/thealgorithms/maths/AmicableNumber.java index 7e7b454ac18a..23c90888ec5d 100644 --- a/src/main/java/com/thealgorithms/maths/AmicableNumber.java +++ b/src/main/java/com/thealgorithms/maths/AmicableNumber.java @@ -15,9 +15,9 @@ *

* link: https://en.wikipedia.org/wiki/Amicable_numbers *

- * Simple Example : (220, 284) - * 220 is divisible by {1,2,4,5,10,11,20,22,44,55,110} <- SUM = 284 - * 284 is divisible by {1,2,4,71,142} <- SUM = 220. + * Simple Example: (220, 284) + * 220 is divisible by {1,2,4,5,10,11,20,22,44,55,110} <-SUM = 284 + * 284 is divisible by {1,2,4,71,142} <-SUM = 220. */ public class AmicableNumber { /** From 593f9c8d3f075cc1802c107953e8d52fff87a318 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Fri, 8 Sep 2023 17:23:51 +0530 Subject: [PATCH 2/4] Update BufferedReader.java --- src/main/java/com/thealgorithms/io/BufferedReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/io/BufferedReader.java b/src/main/java/com/thealgorithms/io/BufferedReader.java index 9b47148976c4..477a52bb5c30 100644 --- a/src/main/java/com/thealgorithms/io/BufferedReader.java +++ b/src/main/java/com/thealgorithms/io/BufferedReader.java @@ -16,7 +16,7 @@ public class BufferedReader { private static final int DEFAULT_BUFFER_SIZE = 5; /** - * The Maximum number of bytes the buffer can hold. + * The maximum number of bytes the buffer can hold. * Value is changed when encountered Eof to not * cause overflow read of 0 bytes */ From 5be1d2c8745ad6e561360cd9a077540369457595 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Thu, 5 Oct 2023 11:47:19 +0530 Subject: [PATCH 3/4] Made the following changes : * Improved readability of files and removed gramatical errors. * Implemented data assigning instead of manually calling arr.ylength in several instances like FindMax, FindMaxRecursion etc. * Removed unwanted params from several files * Implemented Math methods in files math/FindMinRecursion.java and FindMaxRecursion.java --- src/main/java/com/thealgorithms/maths/Average.java | 2 +- .../com/thealgorithms/maths/DeterminantOfMatrix.java | 2 +- src/main/java/com/thealgorithms/maths/DigitalRoot.java | 10 +++++----- .../java/com/thealgorithms/maths/DistanceFormula.java | 4 ++-- .../java/com/thealgorithms/maths/DudeneyNumber.java | 10 +++++----- src/main/java/com/thealgorithms/maths/EulerMethod.java | 2 +- .../java/com/thealgorithms/maths/FindKthNumber.java | 2 +- src/main/java/com/thealgorithms/maths/FindMax.java | 7 ++++--- .../java/com/thealgorithms/maths/FindMaxRecursion.java | 8 ++++---- src/main/java/com/thealgorithms/maths/FindMin.java | 2 +- .../java/com/thealgorithms/maths/FindMinRecursion.java | 7 +++---- src/main/java/com/thealgorithms/maths/GCD.java | 6 +++--- src/main/java/com/thealgorithms/maths/Gaussian.java | 2 +- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Average.java b/src/main/java/com/thealgorithms/maths/Average.java index ad37b78718c3..903afbafe35f 100644 --- a/src/main/java/com/thealgorithms/maths/Average.java +++ b/src/main/java/com/thealgorithms/maths/Average.java @@ -23,7 +23,7 @@ public static double average(double[] numbers) { } /** - * find average value of int array + * find average value of an int array * * @param numbers the array contains element and the sum does not excess long * value limit diff --git a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java index 401bedbccdc0..79b0dafad8f4 100644 --- a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java +++ b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java @@ -4,7 +4,7 @@ /* * @author Ojasva Jain - * Determinant of Matrix Wikipedia link : https://en.wikipedia.org/wiki/Determinant + * Determinant of a Matrix Wikipedia link: https://en.wikipedia.org/wiki/Determinant */ public class DeterminantOfMatrix { diff --git a/src/main/java/com/thealgorithms/maths/DigitalRoot.java b/src/main/java/com/thealgorithms/maths/DigitalRoot.java index 78066f404739..9eeb4a65f2ae 100644 --- a/src/main/java/com/thealgorithms/maths/DigitalRoot.java +++ b/src/main/java/com/thealgorithms/maths/DigitalRoot.java @@ -51,17 +51,17 @@ public static int digitalRoot(int n) { } } - // This function is used for finding the sum of digits of number + // This function is used for finding the sum of the digits of number public static int single(int n) { if (n <= 9) { // if n becomes less than 10 than return n return n; } else { return (n % 10) + single(n / 10); // n % 10 for extracting digits one by one } - } // n / 10 is the number obtainded after removing the digit one by one - // Sum of digits is stored in the Stack memory and then finally returned + } // n / 10 is the number obtained after removing the digit one by one + // The Sum of digits is stored in the Stack memory and then finally returned } /** - * Time Complexity : O((Number of Digits)^2) Auxiliary Space Complexity : - * O(Number of Digits) Constraints : 1 <= n <= 10^7 + * Time Complexity: O((Number of Digits)^2) Auxiliary Space Complexity: + * O(Number of Digits) Constraints: 1 <= n <= 10^7 */ diff --git a/src/main/java/com/thealgorithms/maths/DistanceFormula.java b/src/main/java/com/thealgorithms/maths/DistanceFormula.java index 9a2654dbeedb..6efc2fbdff5d 100644 --- a/src/main/java/com/thealgorithms/maths/DistanceFormula.java +++ b/src/main/java/com/thealgorithms/maths/DistanceFormula.java @@ -16,7 +16,7 @@ public static int hammingDistance(int[] b1, int[] b2) { int d = 0; if (b1.length != b2.length) { - return -1; // error, both array must be have the same length + return -1; // error, both arrays must have the same length } for (int i = 0; i < b1.length; i++) { @@ -31,7 +31,7 @@ public static double minkowskiDistance(double[] p1, double[] p2, int p) { double distance = 0.0; if (p1.length != p2.length) { - return -1; // error, both array must be have the same length + return -1; // error, both arrays must have the same length } for (int i = 0; i < p1.length; i++) { diff --git a/src/main/java/com/thealgorithms/maths/DudeneyNumber.java b/src/main/java/com/thealgorithms/maths/DudeneyNumber.java index 69231af7bb85..3bb56c5ccdb7 100644 --- a/src/main/java/com/thealgorithms/maths/DudeneyNumber.java +++ b/src/main/java/com/thealgorithms/maths/DudeneyNumber.java @@ -16,21 +16,21 @@ public static boolean isDudeney(int n) { if (cube_root * cube_root * cube_root != n) { return false; } - int sum_of_digits = 0; // Stores the sums of the digit of the entered number + int sum_of_digits = 0; // Stores the sums of the digits of the entered number int temp = n; // A temporary variable to store the entered number - // Loop to calculate sum of the digits. + // Loop to calculate the sum of the digits. while (temp > 0) { - // Extracting Last digit of the number + // Extracting the Last digit of the number int rem = temp % 10; - // Calculating sum of digits. + // Calculating the sum of digits. sum_of_digits += rem; // Removing the last digit temp /= 10; } - // If the cube root of the number is not equal to the sum of its digits we return false. + // If the cube root of the number is not equal to the sum of its digits, we return false. return cube_root == sum_of_digits; } } diff --git a/src/main/java/com/thealgorithms/maths/EulerMethod.java b/src/main/java/com/thealgorithms/maths/EulerMethod.java index 336e23dd489c..40e654626a23 100644 --- a/src/main/java/com/thealgorithms/maths/EulerMethod.java +++ b/src/main/java/com/thealgorithms/maths/EulerMethod.java @@ -87,7 +87,7 @@ public static ArrayList eulerFull(double xStart, double xEnd, double s double xCurrent = xStart; while (xCurrent < xEnd) { - // Euler method for next step + // Euler's method for next step yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation); xCurrent += stepSize; double[] point = {xCurrent, yCurrent}; diff --git a/src/main/java/com/thealgorithms/maths/FindKthNumber.java b/src/main/java/com/thealgorithms/maths/FindKthNumber.java index d869ca47c759..bcb83b5ee2fc 100644 --- a/src/main/java/com/thealgorithms/maths/FindKthNumber.java +++ b/src/main/java/com/thealgorithms/maths/FindKthNumber.java @@ -11,7 +11,7 @@ public class FindKthNumber { private static final Random random = new Random(); public static void main(String[] args) { - /* generate array with random size and random elements */ + /* generate an array with random size and random elements */ int[] nums = generateArray(100); /* get 3th largest element */ diff --git a/src/main/java/com/thealgorithms/maths/FindMax.java b/src/main/java/com/thealgorithms/maths/FindMax.java index 76bde5ff600f..0ff2bdd191ac 100644 --- a/src/main/java/com/thealgorithms/maths/FindMax.java +++ b/src/main/java/com/thealgorithms/maths/FindMax.java @@ -12,11 +12,12 @@ private FindMax() { * @return the maximum value stored in the input array */ public static int findMax(final int[] array) { - if (array.length == 0) { - throw new IllegalArgumentException("array must be non-empty."); + int n = array.length; + if (n == 0) { + throw new IllegalArgumentException("Array must be non-empty."); } int max = array[0]; - for (int i = 1; i < array.length; i++) { + for (int i = 1; i < n; i++) { if (array[i] > max) { max = array[i]; } diff --git a/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java b/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java index 574fe5f2b1b8..950a0ebe0085 100644 --- a/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java +++ b/src/main/java/com/thealgorithms/maths/FindMaxRecursion.java @@ -5,7 +5,7 @@ public final class FindMaxRecursion { private FindMaxRecursion() { } /** - * Get max of array using divide and conquer algorithm + * Get max of an array using divide and conquer algorithm * * @param array contains elements * @param low the index of the first element @@ -14,7 +14,7 @@ private FindMaxRecursion() { */ public static int max(final int[] array, final int low, final int high) { if (array.length == 0) { - throw new IllegalArgumentException("array must be non-empty."); + throw new IllegalArgumentException("Array must be non-empty."); } if (low == high) { return array[low]; // or array[high] @@ -25,11 +25,11 @@ public static int max(final int[] array, final int low, final int high) { int leftMax = max(array, low, mid); // get max in [low, mid] int rightMax = max(array, mid + 1, high); // get max in [mid+1, high] - return leftMax < rightMax ? rightMax : leftMax; + return Math.max(leftMax, rightMax); } /** - * Get max of array using recursion algorithm + * Get max of an array using recursion algorithm * * @param array contains elements * @return max value of {@code array} diff --git a/src/main/java/com/thealgorithms/maths/FindMin.java b/src/main/java/com/thealgorithms/maths/FindMin.java index 10a03c801098..76fa2e815ee0 100644 --- a/src/main/java/com/thealgorithms/maths/FindMin.java +++ b/src/main/java/com/thealgorithms/maths/FindMin.java @@ -13,7 +13,7 @@ private FindMin() { */ public static int findMin(final int[] array) { if (array.length == 0) { - throw new IllegalArgumentException("array must be non-empty."); + throw new IllegalArgumentException("Array must be non-empty."); } int min = array[0]; for (int i = 1; i < array.length; i++) { diff --git a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java index 71d7795b7e47..8d1484be0e0b 100644 --- a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java +++ b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java @@ -25,7 +25,7 @@ public static void main(String[] args) { } /** - * Get min of array using divide and conquer algorithm + * Get min of an array using divide and conquer algorithm * * @param array contains elements * @param low the index of the first element @@ -42,14 +42,13 @@ public static int min(int[] array, int low, int high) { int leftMin = min(array, low, mid); // get min in [low, mid] int rightMin = min(array, mid + 1, high); // get min in [mid+1, high] - return leftMin > rightMin ? rightMin : leftMin; + return Math.min(leftMin, rightMin); } /** - * Get min of array using recursion algorithm + * Get min of an array using recursion algorithm * * @param array contains elements - * @param len length of given array * @return min value of {@code array} */ public static int min(int[] array) { diff --git a/src/main/java/com/thealgorithms/maths/GCD.java b/src/main/java/com/thealgorithms/maths/GCD.java index 3a69fcab413f..0f3125bde209 100644 --- a/src/main/java/com/thealgorithms/maths/GCD.java +++ b/src/main/java/com/thealgorithms/maths/GCD.java @@ -1,15 +1,15 @@ package com.thealgorithms.maths; /** - * This is Euclid's algorithm which is used to find the greatest common - * denominator Overide function name gcd + * This is Euclid's algorithm, used to find the greatest common + * denominator Override function name gcd * * @author Oskar Enmalm 3/10/17 */ public class GCD { /** - * get greatest common divisor + * get the greatest common divisor * * @param num1 the first number * @param num2 the second number diff --git a/src/main/java/com/thealgorithms/maths/Gaussian.java b/src/main/java/com/thealgorithms/maths/Gaussian.java index fd0f86d89f89..442c51e9d32d 100644 --- a/src/main/java/com/thealgorithms/maths/Gaussian.java +++ b/src/main/java/com/thealgorithms/maths/Gaussian.java @@ -38,7 +38,7 @@ public static double[][] gaussianElimination(int mat_size, int i, double[][] mat return mat; } - // calculate the x_1, x_2,... values of the gaussian and save it in an arraylist. + // calculate the x_1, x_2, ... values of the gaussian and save it in an arraylist. public static ArrayList valueOfGaussian(int mat_size, double[][] x, double[][] mat) { ArrayList answerArray = new ArrayList(); int i, j; From cc01c1b40c7024e9c763f8224aaad1da4da34edc Mon Sep 17 00:00:00 2001 From: Debasish Biswas Date: Sat, 7 Oct 2023 19:13:46 +0530 Subject: [PATCH 4/4] Update src/main/java/com/thealgorithms/maths/FindMinRecursion.java --- src/main/java/com/thealgorithms/maths/FindMinRecursion.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java index 19eb479f6b61..a2cf1b36d6cb 100644 --- a/src/main/java/com/thealgorithms/maths/FindMinRecursion.java +++ b/src/main/java/com/thealgorithms/maths/FindMinRecursion.java @@ -18,7 +18,6 @@ public static int min(final int[] array, final int low, final int high) { if (array.length == 0) { throw new IllegalArgumentException("array must be non-empty."); } - if (low == high) { return array[low]; // or array[high] }