diff --git a/checkstyle.xml b/checkstyle.xml
index de7c70266bfb..5ada9361d03c 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -114,7 +114,7 @@
-
+
diff --git a/src/main/java/com/thealgorithms/backtracking/PowerSum.java b/src/main/java/com/thealgorithms/backtracking/PowerSum.java
index 8c46fb1c924a..6617ea326a1c 100644
--- a/src/main/java/com/thealgorithms/backtracking/PowerSum.java
+++ b/src/main/java/com/thealgorithms/backtracking/PowerSum.java
@@ -11,30 +11,30 @@ public class PowerSum {
private int count = 0;
private int sum = 0;
- public int powSum(int N, int X) {
- sum(N, X, 1);
+ public int powSum(int n, int x) {
+ sum(n, x, 1);
return count;
}
// here i is the natural number which will be raised by X and added in sum.
- public void sum(int N, int X, int i) {
+ public void sum(int n, int x, int i) {
// if sum is equal to N that is one of our answer and count is increased.
- if (sum == N) {
+ if (sum == n) {
count++;
return;
} // we will be adding next natural number raised to X only if on adding it in sum the
// result is less than N.
- else if (sum + power(i, X) <= N) {
- sum += power(i, X);
- sum(N, X, i + 1);
+ else if (sum + power(i, x) <= n) {
+ sum += power(i, x);
+ sum(n, x, i + 1);
// backtracking and removing the number added last since no possible combination is
// there with it.
- sum -= power(i, X);
+ sum -= power(i, x);
}
- if (power(i, X) < N) {
+ if (power(i, x) < n) {
// calling the sum function with next natural number after backtracking if when it is
// raised to X is still less than X.
- sum(N, X, i + 1);
+ sum(n, x, i + 1);
}
}
diff --git a/src/main/java/com/thealgorithms/conversions/RomanToInteger.java b/src/main/java/com/thealgorithms/conversions/RomanToInteger.java
index 6ffb41c3c0e2..cf2d4145858f 100644
--- a/src/main/java/com/thealgorithms/conversions/RomanToInteger.java
+++ b/src/main/java/com/thealgorithms/conversions/RomanToInteger.java
@@ -24,31 +24,31 @@ private RomanToInteger() {
/**
* This function convert Roman number into Integer
*
- * @param A Roman number string
+ * @param a Roman number string
* @return integer
*/
- public static int romanToInt(String A) {
- A = A.toUpperCase();
+ public static int romanToInt(String a) {
+ a = a.toUpperCase();
char prev = ' ';
int sum = 0;
int newPrev = 0;
- for (int i = A.length() - 1; i >= 0; i--) {
- char c = A.charAt(i);
+ for (int i = a.length() - 1; i >= 0; i--) {
+ char c = a.charAt(i);
if (prev != ' ') {
- // checking current Number greater then previous or not
+ // checking current Number greater than previous or not
newPrev = ROMAN_TO_INT.get(prev) > newPrev ? ROMAN_TO_INT.get(prev) : newPrev;
}
int currentNum = ROMAN_TO_INT.get(c);
- // if current number greater then prev max previous then add
+ // if current number greater than prev max previous then add
if (currentNum >= newPrev) {
sum += currentNum;
} else {
- // subtract upcoming number until upcoming number not greater then prev max
+ // subtract upcoming number until upcoming number not greater than prev max
sum -= currentNum;
}
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java b/src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java
index 1e82ca0cd421..4cc14bfd38de 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java
@@ -18,14 +18,14 @@ public final class BipartiteGrapfDFS {
private BipartiteGrapfDFS() {
}
- private static boolean bipartite(int V, ArrayList> adj, int[] color, int node) {
+ private static boolean bipartite(int v, ArrayList> adj, int[] color, int node) {
if (color[node] == -1) {
color[node] = 1;
}
for (Integer it : adj.get(node)) {
if (color[it] == -1) {
color[it] = 1 - color[node];
- if (!bipartite(V, adj, color, it)) {
+ if (!bipartite(v, adj, color, it)) {
return false;
}
} else if (color[it] == color[node]) {
@@ -35,14 +35,14 @@ private static boolean bipartite(int V, ArrayList> adj, int[]
return true;
}
- public static boolean isBipartite(int V, ArrayList> adj) {
+ public static boolean isBipartite(int v, ArrayList> adj) {
// Code here
- int[] color = new int[V + 1];
+ int[] color = new int[v + 1];
Arrays.fill(color, -1);
- for (int i = 0; i < V; i++) {
+ for (int i = 0; i < v; i++) {
if (color[i] == -1) {
- if (!bipartite(V, adj, color, i)) {
+ if (!bipartite(v, adj, color, i)) {
return false;
}
}
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java b/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
index a574b40daec6..d47ffe3aa27d 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
@@ -15,10 +15,10 @@ public FloydWarshall(int numberofvertices) {
this.numberofvertices = numberofvertices;
}
- public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
+ public void floydwarshall(int[][] adjacencyMatrix) { // calculates all the distances from source to destination vertex
for (int source = 1; source <= numberofvertices; source++) {
for (int destination = 1; destination <= numberofvertices; destination++) {
- distanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
+ distanceMatrix[source][destination] = adjacencyMatrix[source][destination];
}
}
for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
index 251c169d11ac..987e73a2a5d5 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
@@ -60,7 +60,7 @@ public class TarjansAlgorithm {
private List> sccList = new ArrayList>();
- public List> stronglyConnectedComponents(int V, List> graph) {
+ public List> stronglyConnectedComponents(int v, List> graph) {
// Initially all vertices as unvisited, insertion and low time are undefined
@@ -68,20 +68,20 @@ public List> stronglyConnectedComponents(int V, List
// lowTime: indicates the earliest visited vertex (the vertex with minimum insertion time)
// that can be reached from a subtree rooted with a particular node.
- int[] lowTime = new int[V];
- int[] insertionTime = new int[V];
- for (int i = 0; i < V; i++) {
+ int[] lowTime = new int[v];
+ int[] insertionTime = new int[v];
+ for (int i = 0; i < v; i++) {
insertionTime[i] = -1;
lowTime[i] = -1;
}
// To check if element is present in stack
- boolean[] isInStack = new boolean[V];
+ boolean[] isInStack = new boolean[v];
// Store nodes during DFS
Stack st = new Stack();
- for (int i = 0; i < V; i++) {
+ for (int i = 0; i < v; i++) {
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
}
diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java
index 5a1ab7b6174b..9fbb2ff0ad62 100644
--- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java
+++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java
@@ -19,8 +19,8 @@ public GenericHashMapUsingArray() {
// 75, then adding 76th item it will double the size, copy all elements
// & then add 76th item.
- private void initBuckets(int N) {
- buckets = new LinkedList[N];
+ private void initBuckets(int n) {
+ buckets = new LinkedList[n];
for (int i = 0; i < buckets.length; i++) {
buckets[i] = new LinkedList<>();
}
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java b/src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java
index d98335b1e5b9..a714eda18bcd 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java
@@ -13,15 +13,15 @@ public class Merge_K_SortedLinkedlist {
* This function merge K sorted LinkedList
*
* @param a array of LinkedList
- * @param N size of array
+ * @param n size of array
* @return node
*/
- Node mergeKList(Node[] a, int N) {
+ Node mergeKList(Node[] a, int n) {
// Min Heap
PriorityQueue min = new PriorityQueue<>(Comparator.comparingInt(x -> x.data));
// adding head of all linkedList in min heap
- min.addAll(Arrays.asList(a).subList(0, N));
+ min.addAll(Arrays.asList(a).subList(0, n));
// Make new head among smallest heads in K linkedList
Node head = min.poll();
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java b/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java
index a6a76f8f094f..57b3edc163ca 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java
@@ -32,16 +32,16 @@ public final int constructTree(int[] arr, int start, int end, int index) {
/* A function which will update the value at a index i. This will be called by the
update function internally*/
- private void updateTree(int start, int end, int index, int diff, int seg_index) {
+ private void updateTree(int start, int end, int index, int diff, int segIndex) {
if (index < start || index > end) {
return;
}
- this.segTree[seg_index] += diff;
+ this.segTree[segIndex] += diff;
if (start != end) {
int mid = start + (end - start) / 2;
- updateTree(start, mid, index, diff, seg_index * 2 + 1);
- updateTree(mid + 1, end, index, diff, seg_index * 2 + 2);
+ updateTree(start, mid, index, diff, segIndex * 2 + 1);
+ updateTree(mid + 1, end, index, diff, segIndex * 2 + 2);
}
}
@@ -58,17 +58,17 @@ public void update(int index, int value) {
/* A function to get the sum of the elements from index l to index r. This will be called
* internally*/
- private int getSumTree(int start, int end, int q_start, int q_end, int seg_index) {
- if (q_start <= start && q_end >= end) {
- return this.segTree[seg_index];
+ private int getSumTree(int start, int end, int qStart, int qEnd, int segIndex) {
+ if (qStart <= start && qEnd >= end) {
+ return this.segTree[segIndex];
}
- if (q_start > end || q_end < start) {
+ if (qStart > end || qEnd < start) {
return 0;
}
int mid = start + (end - start) / 2;
- return (getSumTree(start, mid, q_start, q_end, seg_index * 2 + 1) + getSumTree(mid + 1, end, q_start, q_end, seg_index * 2 + 2));
+ return (getSumTree(start, mid, qStart, qEnd, segIndex * 2 + 1) + getSumTree(mid + 1, end, qStart, qEnd, segIndex * 2 + 2));
}
/* A function to query the sum of the subarray [start...end]*/
diff --git a/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java b/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java
index 7c28797c0791..de829585891a 100644
--- a/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java
+++ b/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java
@@ -27,15 +27,15 @@ public static long calculatePower(long x, long y) {
}
// iterative function to calculate a to the power of b
- long power(long N, long M) {
- long power = N;
+ long power(long n, long m) {
+ long power = n;
long sum = 1;
- while (M > 0) {
- if ((M & 1) == 1) {
+ while (m > 0) {
+ if ((m & 1) == 1) {
sum *= power;
}
power = power * power;
- M = M >> 1;
+ m = m >> 1;
}
return sum;
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
index 7fa4e24383a8..3fa8728930cb 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java
@@ -12,44 +12,44 @@ private BoundaryFill() {
* Get the color at the given co-odrinates of a 2D image
*
* @param image The image to be filled
- * @param x_co_ordinate The x co-ordinate of which color is to be obtained
- * @param y_co_ordinate The y co-ordinate of which color is to be obtained
+ * @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
*/
- public static int getPixel(int[][] image, int x_co_ordinate, int y_co_ordinate) {
- return image[x_co_ordinate][y_co_ordinate];
+ public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
+ return image[xCoordinate][yCoordinate];
}
/**
* Put the color at the given co-odrinates of a 2D image
*
* @param image The image to be filed
- * @param x_co_ordinate The x co-ordinate at which color is to be filled
- * @param y_co_ordinate The y co-ordinate at which color is to be filled
+ * @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
*/
- public static void putPixel(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color) {
- image[x_co_ordinate][y_co_ordinate] = new_color;
+ public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int newColor) {
+ image[xCoordinate][yCoordinate] = newColor;
}
/**
* Fill the 2D image with new color
*
* @param image The image to be filed
- * @param x_co_ordinate The x co-ordinate at which color is to be filled
- * @param y_co_ordinate The y co-ordinate at which color is to be filled
- * @param new_color The new color which to be filled in the image
- * @param boundary_color The old color which is to be replaced in the image
+ * @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 x_co_ordinate, int y_co_ordinate, int new_color, int boundary_color) {
- if (x_co_ordinate >= 0 && y_co_ordinate >= 0 && getPixel(image, x_co_ordinate, y_co_ordinate) != new_color && getPixel(image, x_co_ordinate, y_co_ordinate) != boundary_color) {
- putPixel(image, x_co_ordinate, y_co_ordinate, new_color);
- boundaryFill(image, x_co_ordinate + 1, y_co_ordinate, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate - 1, y_co_ordinate, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate, y_co_ordinate + 1, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate, y_co_ordinate - 1, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate + 1, y_co_ordinate - 1, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate - 1, y_co_ordinate + 1, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate + 1, y_co_ordinate + 1, new_color, boundary_color);
- boundaryFill(image, x_co_ordinate - 1, y_co_ordinate - 1, new_color, boundary_color);
+ public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
+ if (xCoordinate >= 0 && yCoordinate >= 0 && getPixel(image, xCoordinate, yCoordinate) != newColor && getPixel(image, xCoordinate, yCoordinate) != boundaryColor) {
+ putPixel(image, xCoordinate, yCoordinate, newColor);
+ boundaryFill(image, xCoordinate + 1, yCoordinate, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate - 1, yCoordinate, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate, yCoordinate + 1, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate, yCoordinate - 1, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate + 1, yCoordinate - 1, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate - 1, yCoordinate + 1, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate + 1, yCoordinate + 1, newColor, boundaryColor);
+ boundaryFill(image, xCoordinate - 1, yCoordinate - 1, newColor, boundaryColor);
}
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java b/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
index 1daac91c5b4b..b433c44b9077 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java
@@ -8,9 +8,9 @@ private BruteForceKnapsack() {
// Returns the maximum value that
// can be put in a knapsack of
// capacity W
- static int knapSack(int W, int[] wt, int[] val, int n) {
+ static int knapSack(int w, int[] wt, int[] val, int n) {
// Base Case
- if (n == 0 || W == 0) {
+ if (n == 0 || w == 0) {
return 0;
}
@@ -18,13 +18,13 @@ static int knapSack(int W, int[] wt, int[] val, int n) {
// more than Knapsack capacity W,
// then this item cannot be included
// in the optimal solution
- if (wt[n - 1] > W) {
- return knapSack(W, wt, val, n - 1);
+ if (wt[n - 1] > w) {
+ return knapSack(w, wt, val, n - 1);
} // Return the maximum of two cases:
// (1) nth item included
// (2) not included
else {
- return Math.max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), knapSack(W, wt, val, n - 1));
+ return Math.max(val[n - 1] + knapSack(w - wt[n - 1], wt, val, n - 1), knapSack(w, wt, val, n - 1));
}
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
index e1f0aeabe14d..de75126044ae 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
@@ -10,7 +10,7 @@ public final class KadaneAlgorithm {
private KadaneAlgorithm() {
}
- public static boolean maxSum(int[] a, int predicted_answer) {
+ public static boolean maxSum(int[] a, int predictedAnswer) {
int sum = a[0];
int runningSum = 0;
for (int k : a) {
@@ -22,7 +22,7 @@ public static boolean maxSum(int[] a, int predicted_answer) {
// if running sum is negative then it is initialized to zero
}
// for-each loop is used to iterate over the array and find the maximum subarray sum
- return sum == predicted_answer;
+ return sum == predictedAnswer;
// It returns true if sum and predicted answer matches
// The predicted answer is the answer itself. So it always return true
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
index 7bc383656581..5d31d40dacdc 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
@@ -12,7 +12,7 @@ public final class NewManShanksPrime {
private NewManShanksPrime() {
}
- public static boolean nthManShanksPrime(int n, int expected_answer) {
+ public static boolean nthManShanksPrime(int n, int expectedAnswer) {
int[] a = new int[n + 1];
// array of n+1 size is initialized
a[0] = 1;
@@ -22,7 +22,7 @@ public static boolean nthManShanksPrime(int n, int expected_answer) {
a[i] = 2 * a[i - 1] + a[i - 2];
}
// The loop is continued till n
- return a[n] == expected_answer;
+ return a[n] == expectedAnswer;
// returns true if calculated answer matches with expected answer
}
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
index a2e641095c9f..dd48008bd21e 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SumOfSubset.java
@@ -4,16 +4,16 @@ public final class SumOfSubset {
private SumOfSubset() {
}
- public static boolean subsetSum(int[] arr, int num, int Key) {
- if (Key == 0) {
+ public static boolean subsetSum(int[] arr, int num, int key) {
+ if (key == 0) {
return true;
}
- if (num < 0 || Key < 0) {
+ if (num < 0 || key < 0) {
return false;
}
- boolean include = subsetSum(arr, num - 1, Key - arr[num]);
- boolean exclude = subsetSum(arr, num - 1, Key);
+ boolean include = subsetSum(arr, num - 1, key - arr[num]);
+ boolean exclude = subsetSum(arr, num - 1, key);
return include || exclude;
}
diff --git a/src/main/java/com/thealgorithms/maths/Convolution.java b/src/main/java/com/thealgorithms/maths/Convolution.java
index 4dd4eb3e99f5..93e103f8c7cf 100644
--- a/src/main/java/com/thealgorithms/maths/Convolution.java
+++ b/src/main/java/com/thealgorithms/maths/Convolution.java
@@ -15,12 +15,12 @@ private Convolution() {
* signal must start from 0. If you have a signal that has values before 0
* then shift it to start from 0.
*
- * @param A The first discrete signal
- * @param B The second discrete signal
+ * @param a The first discrete signal
+ * @param b The second discrete signal
* @return The convolved signal
*/
- public static double[] convolution(double[] A, double[] B) {
- double[] convolved = new double[A.length + B.length - 1];
+ public static double[] convolution(double[] a, double[] b) {
+ double[] convolved = new double[a.length + b.length - 1];
/*
The discrete convolution of two signals A and B is defined as:
@@ -35,10 +35,10 @@ public static double[] convolution(double[] A, double[] B) {
*/
for (int i = 0; i < convolved.length; i++) {
convolved[i] = 0;
- int k = Math.max(i - B.length + 1, 0);
+ int k = Math.max(i - b.length + 1, 0);
- while (k < i + 1 && k < A.length) {
- convolved[i] += A[k] * B[i - k];
+ while (k < i + 1 && k < a.length) {
+ convolved[i] += a[k] * b[i - k];
k++;
}
}
diff --git a/src/main/java/com/thealgorithms/maths/Gaussian.java b/src/main/java/com/thealgorithms/maths/Gaussian.java
index 07c0f67f06e2..cefbaea5b9b4 100644
--- a/src/main/java/com/thealgorithms/maths/Gaussian.java
+++ b/src/main/java/com/thealgorithms/maths/Gaussian.java
@@ -6,34 +6,34 @@ public final class Gaussian {
private Gaussian() {
}
- public static ArrayList gaussian(int mat_size, ArrayList matrix) {
+ public static ArrayList gaussian(int matSize, ArrayList matrix) {
ArrayList answerArray = new ArrayList();
int i;
int j = 0;
- double[][] mat = new double[mat_size + 1][mat_size + 1];
- double[][] x = new double[mat_size][mat_size + 1];
+ double[][] mat = new double[matSize + 1][matSize + 1];
+ double[][] x = new double[matSize][matSize + 1];
// Values from arraylist to matrix
- for (i = 0; i < mat_size; i++) {
- for (j = 0; j <= mat_size; j++) {
+ for (i = 0; i < matSize; i++) {
+ for (j = 0; j <= matSize; j++) {
mat[i][j] = matrix.get(i);
}
}
- mat = gaussianElimination(mat_size, i, mat);
- answerArray = valueOfGaussian(mat_size, x, mat);
+ mat = gaussianElimination(matSize, i, mat);
+ answerArray = valueOfGaussian(matSize, x, mat);
return answerArray;
}
// Perform Gaussian elimination
- public static double[][] gaussianElimination(int mat_size, int i, double[][] mat) {
+ public static double[][] gaussianElimination(int matSize, int i, double[][] mat) {
int step = 0;
- for (step = 0; step < mat_size - 1; step++) {
- for (i = step; i < mat_size - 1; i++) {
+ for (step = 0; step < matSize - 1; step++) {
+ for (i = step; i < matSize - 1; i++) {
double a = (mat[i + 1][step] / mat[step][step]);
- for (int j = step; j <= mat_size; j++) {
+ for (int j = step; j <= matSize; j++) {
mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]);
}
}
@@ -42,27 +42,27 @@ public static double[][] gaussianElimination(int mat_size, int i, double[][] mat
}
// 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) {
+ public static ArrayList valueOfGaussian(int matSize, double[][] x, double[][] mat) {
ArrayList answerArray = new ArrayList();
int i;
int j;
- for (i = 0; i < mat_size; i++) {
- for (j = 0; j <= mat_size; j++) {
+ for (i = 0; i < matSize; i++) {
+ for (j = 0; j <= matSize; j++) {
x[i][j] = mat[i][j];
}
}
- for (i = mat_size - 1; i >= 0; i--) {
+ for (i = matSize - 1; i >= 0; i--) {
double sum = 0;
- for (j = mat_size - 1; j > i; j--) {
+ for (j = matSize - 1; j > i; j--) {
x[i][j] = x[j][j] * x[i][j];
sum = x[i][j] + sum;
}
if (x[i][i] == 0) {
x[i][i] = 0;
} else {
- x[i][i] = (x[i][mat_size] - sum) / (x[i][i]);
+ x[i][i] = (x[i][matSize] - sum) / (x[i][i]);
}
answerArray.add(x[i][j]);
}
diff --git a/src/main/java/com/thealgorithms/maths/PronicNumber.java b/src/main/java/com/thealgorithms/maths/PronicNumber.java
index 1ae53c4c4429..4891cf3c63b3 100644
--- a/src/main/java/com/thealgorithms/maths/PronicNumber.java
+++ b/src/main/java/com/thealgorithms/maths/PronicNumber.java
@@ -17,14 +17,14 @@ private PronicNumber() {
/**
* This method checks if the given number is pronic number or non-pronic number
*
- * @param input_number Integer value which is to be checked if is a pronic number or not
+ * @param inputNumber Integer value which is to be checked if is a pronic number or not
* @return true if input number is a pronic number, false otherwise
*/
- static boolean isPronic(int input_number) {
+ static boolean isPronic(int inputNumber) {
// Iterating from 0 to input_number
- for (int i = 0; i <= input_number; i++) {
+ for (int i = 0; i <= inputNumber; i++) {
// Checking if product of i and (i+1) is equals input_number
- if (i * (i + 1) == input_number && i != input_number) {
+ if (i * (i + 1) == inputNumber && i != inputNumber) {
// return true if product of i and (i+1) is equals input_number
return true;
}
diff --git a/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java b/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
index 8b93702b9514..e2769744bcda 100644
--- a/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
+++ b/src/main/java/com/thealgorithms/maths/VectorCrossProduct.java
@@ -55,14 +55,14 @@ public class VectorCrossProduct {
/**
* constructor, initialises Vector with given Direction Ratios
*
- * @param _x set to x
- * @param _y set to y
- * @param _z set to z
+ * @param vectorX set to x
+ * @param vectorY set to y
+ * @param vectorZ set to z
*/
- VectorCrossProduct(int _x, int _y, int _z) {
- x = _x;
- y = _y;
- z = _z;
+ VectorCrossProduct(int vectorX, int vectorY, int vectorZ) {
+ x = vectorX;
+ y = vectorY;
+ z = vectorZ;
}
/**
diff --git a/src/main/java/com/thealgorithms/others/KMP.java b/src/main/java/com/thealgorithms/others/KMP.java
index 7df5d1a8a5bd..73eaf2fc9beb 100644
--- a/src/main/java/com/thealgorithms/others/KMP.java
+++ b/src/main/java/com/thealgorithms/others/KMP.java
@@ -39,17 +39,17 @@ public static void kmpMatcher(final String haystack, final String needle) {
}
// return the prefix function
- private static int[] computePrefixFunction(final String P) {
- final int n = P.length();
+ private static int[] computePrefixFunction(final String p) {
+ final int n = p.length();
final int[] pi = new int[n];
pi[0] = 0;
int q = 0;
for (int i = 1; i < n; i++) {
- while (q > 0 && P.charAt(q) != P.charAt(i)) {
+ while (q > 0 && p.charAt(q) != p.charAt(i)) {
q = pi[q - 1];
}
- if (P.charAt(q) == P.charAt(i)) {
+ if (p.charAt(q) == p.charAt(i)) {
q++;
}
diff --git a/src/main/java/com/thealgorithms/others/PasswordGen.java b/src/main/java/com/thealgorithms/others/PasswordGen.java
index f982848a5c1a..7d21f112d480 100644
--- a/src/main/java/com/thealgorithms/others/PasswordGen.java
+++ b/src/main/java/com/thealgorithms/others/PasswordGen.java
@@ -15,7 +15,7 @@ final class PasswordGen {
private PasswordGen() {
}
- static String generatePassword(int min_length, int max_length) {
+ static String generatePassword(int minLength, int maxLength) {
Random random = new Random();
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -35,7 +35,7 @@ static String generatePassword(int min_length, int max_length) {
StringBuilder password = new StringBuilder();
// Note that size of the password is also random
- for (int i = random.nextInt(max_length - min_length) + min_length; i > 0; --i) {
+ for (int i = random.nextInt(maxLength - minLength) + minLength; i > 0; --i) {
password.append(letters.get(random.nextInt(letters.size())));
}
diff --git a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
index c14c91ba6c37..ca2144e4924f 100644
--- a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java
@@ -83,28 +83,28 @@ 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
+ * @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
*/
- private ProcessDetails findShortestJob(ArrayList ReadyProcesses) {
- if (ReadyProcesses.isEmpty()) {
+ private ProcessDetails findShortestJob(ArrayList readyProcesses) {
+ if (readyProcesses.isEmpty()) {
return null;
}
int i;
- int size = ReadyProcesses.size();
- int minBurstTime = ReadyProcesses.get(0).getBurstTime();
+ int size = readyProcesses.size();
+ int minBurstTime = readyProcesses.get(0).getBurstTime();
int temp;
int positionOfShortestJob = 0;
for (i = 1; i < size; i++) {
- temp = ReadyProcesses.get(i).getBurstTime();
+ temp = readyProcesses.get(i).getBurstTime();
if (minBurstTime > temp) {
minBurstTime = temp;
positionOfShortestJob = i;
}
}
- return ReadyProcesses.get(positionOfShortestJob);
+ return readyProcesses.get(positionOfShortestJob);
}
}
diff --git a/src/main/java/com/thealgorithms/sorts/BitonicSort.java b/src/main/java/com/thealgorithms/sorts/BitonicSort.java
index 346d860508ca..b4b26299562f 100644
--- a/src/main/java/com/thealgorithms/sorts/BitonicSort.java
+++ b/src/main/java/com/thealgorithms/sorts/BitonicSort.java
@@ -55,8 +55,8 @@ void bitonicSort(int[] a, int low, int cnt, int dir) {
/*Caller of bitonicSort for sorting the entire array
of length N in ASCENDING order */
- void sort(int[] a, int N, int up) {
- bitonicSort(a, 0, N, up);
+ void sort(int[] a, int n, int up) {
+ bitonicSort(a, 0, n, up);
}
/* A utility function to print array of size n */