Skip to content

style: enable ParameterName in CheckStyle. #5196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<!-- TODO <module name="ParameterName"/> -->
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<!-- TODO <module name="TypeName"/> -->

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/thealgorithms/backtracking/PowerSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public final class BipartiteGrapfDFS {
private BipartiteGrapfDFS() {
}

private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
private static boolean bipartite(int v, ArrayList<ArrayList<Integer>> 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]) {
Expand All @@ -35,14 +35,14 @@ private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[]
return true;
}

public static boolean isBipartite(int V, ArrayList<ArrayList<Integer>> adj) {
public static boolean isBipartite(int v, ArrayList<ArrayList<Integer>> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ public class TarjansAlgorithm {

private List<List<Integer>> sccList = new ArrayList<List<Integer>>();

public List<List<Integer>> stronglyConnectedComponents(int V, List<List<Integer>> graph) {
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {

// Initially all vertices as unvisited, insertion and low time are undefined

// insertionTime:Time when a node is visited 1st time while DFS traversal

// 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<Integer> st = new Stack<Integer>();

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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]*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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;
}

// If weight of the nth item is
// 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
Loading