Skip to content

style: enable MethodName in CheckStyle #5182

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 1 commit into from
May 27, 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 @@ -112,7 +112,7 @@
<module name="LocalFinalVariableName"/>
<!-- TODO <module name="LocalVariableName"/> -->
<!-- TODO <module name="MemberName"/> -->
<!-- TODO <module name="MethodName"/> -->
<module name="MethodName"/>
<module name="PackageName"/>
<!-- TODO <module name="ParameterName"/> -->
<module name="StaticVariableName"/>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/thealgorithms/backtracking/PowerSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class PowerSum {
private int sum = 0;

public int powSum(int N, int X) {
Sum(N, X, 1);
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) {
count++;
Expand All @@ -26,15 +26,15 @@ public void Sum(int N, int X, int i) {
// result is less than N.
else if (sum + power(i, X) <= N) {
sum += power(i, X);
Sum(N, X, i + 1);
sum(N, X, i + 1);
// backtracking and removing the number added last since no possible combination is
// there with it.
sum -= power(i, X);
}
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
6 changes: 3 additions & 3 deletions src/main/java/com/thealgorithms/ciphers/DES.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private String[] getSubkeys(String originalKey) {
return subKeys;
}

private String XOR(String a, String b) {
private String xOR(String a, String b) {
int i;
int l = a.length();
StringBuilder xor = new StringBuilder();
Expand Down Expand Up @@ -143,7 +143,7 @@ private String feistel(String messageBlock, String key) {
for (i = 0; i < 48; i++) {
expandedKey.append(messageBlock.charAt(EXPANSION[i] - 1));
}
String mixedKey = XOR(expandedKey.toString(), key);
String mixedKey = xOR(expandedKey.toString(), key);
StringBuilder substitutedString = new StringBuilder();

// Let us now use the s-boxes to transform each 6 bit (length here) block to 4 bits
Expand Down Expand Up @@ -175,7 +175,7 @@ private String encryptBlock(String message, String[] keys) {
// Iterate 16 times
for (i = 0; i < 16; i++) {
String Ln = R0; // Previous Right block
String Rn = XOR(L0, feistel(R0, keys[i]));
String Rn = xOR(L0, feistel(R0, keys[i]));
L0 = Ln;
R0 = Rn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void insert(int a) {
}

// Returns and removes the minimum element in the heap
public int extract_min() {
public int extractMin() {
// If is empty return -1
if (isEmpty()) return -1;

Expand All @@ -101,17 +101,17 @@ public int extract_min() {
}

// Function returning a list of an in order traversal of the data structure
public ArrayList<Integer> in_order() {
public ArrayList<Integer> inOrder() {
ArrayList<Integer> lst = new ArrayList<>();
in_order_aux(root, lst);
inOrderAux(root, lst);
return new ArrayList<>(lst);
}

// Auxiliary function for in_order
private void in_order_aux(Node n, ArrayList<Integer> lst) {
private void inOrderAux(Node n, ArrayList<Integer> lst) {
if (n == null) return;
in_order_aux(n.left, lst);
inOrderAux(n.left, lst);
lst.add(n.element);
in_order_aux(n.right, lst);
inOrderAux(n.right, lst);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ private static final class Node {
private final Node root;
public GenericTree() { // Constructor
Scanner scn = new Scanner(System.in);
root = create_treeG(null, 0, scn);
root = createTreeG(null, 0, scn);
}

private Node create_treeG(Node node, int childIndex, Scanner scanner) {
private Node createTreeG(Node node, int childIndex, Scanner scanner) {
// display
if (node == null) {
System.out.println("Enter root's data");
Expand All @@ -41,7 +41,7 @@ private Node create_treeG(Node node, int childIndex, Scanner scanner) {
System.out.println("number of children");
int number = scanner.nextInt();
for (int i = 0; i < number; i++) {
Node child = create_treeG(node, i, scanner);
Node child = createTreeG(node, i, scanner);
node.child.add(child);
}
return node;
Expand All @@ -51,17 +51,17 @@ private Node create_treeG(Node node, int childIndex, Scanner scanner) {
* Function to display the generic tree
*/
public void display() { // Helper function
display_1(root);
display1(root);
}

private void display_1(Node parent) {
private void display1(Node parent) {
System.out.print(parent.data + "=>");
for (int i = 0; i < parent.child.size(); i++) {
System.out.print(parent.child.get(i).data + " ");
}
System.out.println(".");
for (int i = 0; i < parent.child.size(); i++) {
display_1(parent.child.get(i));
display1(parent.child.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private NearestRightKey() {
}

public static void main(String[] args) {
NRKTree root = BuildTree();
NRKTree root = buildTree();
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int inputX0 = sc.nextInt();
Expand All @@ -17,7 +17,7 @@ public static void main(String[] args) {
sc.close();
}

public static NRKTree BuildTree() {
public static NRKTree buildTree() {
int randomX = ThreadLocalRandom.current().nextInt(0, 100 + 1);
NRKTree root = new NRKTree(null, null, randomX);

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 max_Sum(int[] a, int predicted_answer) {
public static boolean maxSum(int[] a, int predicted_answer) {
int sum = a[0];
int running_sum = 0;
for (int k : a) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private LongestAlternatingSubsequence() {
}

/* Function to return longest alternating subsequence length*/
static int AlternatingLength(int[] arr, int n) {
static int alternatingLength(int[] arr, int n) {
/*

las[i][0] = Length of the longest
Expand Down Expand Up @@ -68,6 +68,6 @@ public static void main(String[] args) {
int[] arr = {10, 22, 9, 33, 49, 50, 31, 60};
int n = arr.length;
System.out.println("Length of Longest "
+ "alternating subsequence is " + AlternatingLength(arr, n));
+ "alternating subsequence is " + alternatingLength(arr, n));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static int upperBound(int[] ar, int l, int r, int key) {
return r;
}

public static int LIS(int[] array) {
public static int lis(int[] array) {
int N = array.length;
if (N == 0) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static void main(String[] args) {
String a = "BBABCBCAB";
String b = "BABCBAB";

String aLPS = LPS(a);
String bLPS = LPS(b);
String aLPS = lps(a);
String bLPS = lps(b);

System.out.println(a + " => " + aLPS);
System.out.println(b + " => " + bLPS);
}

public static String LPS(String original) throws IllegalArgumentException {
public static String lps(String original) throws IllegalArgumentException {
StringBuilder reverse = new StringBuilder(original);
reverse = reverse.reverse();
return recursiveLPS(original, reverse.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public static void main(String[] args) {
String a = "babad";
String b = "cbbd";

String aLPS = LPS(a);
String bLPS = LPS(b);
String aLPS = lps(a);
String bLPS = lps(b);

System.out.println(a + " => " + aLPS);
System.out.println(b + " => " + bLPS);
}

private static String LPS(String input) {
private static String lps(String input) {
if (input == null || input.length() == 0) {
return input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public final class MatrixChainRecursiveTopDownMemoisation {
private MatrixChainRecursiveTopDownMemoisation() {
}

static int Memoized_Matrix_Chain(int[] p) {
static int memoizedMatrixChain(int[] p) {
int n = p.length;
int[][] m = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
m[i][j] = Integer.MAX_VALUE;
}
}
return Lookup_Chain(m, p, 1, n - 1);
return lookupChain(m, p, 1, n - 1);
}

static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
static int lookupChain(int[][] m, int[] p, int i, int j) {
if (i == j) {
m[i][j] = 0;
return m[i][j];
Expand All @@ -30,7 +30,7 @@ static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
return m[i][j];
} else {
for (int k = i; k < j; k++) {
int q = Lookup_Chain(m, p, i, k) + Lookup_Chain(m, p, k + 1, j) + (p[i - 1] * p[k] * p[j]);
int q = lookupChain(m, p, i, k) + lookupChain(m, p, k + 1, j) + (p[i - 1] * p[k] * p[j]);
if (q < m[i][j]) {
m[i][j] = q;
}
Expand All @@ -43,6 +43,6 @@ static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
// respectively output should be Minimum number of multiplications is 38
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
System.out.println("Minimum number of multiplications is " + Memoized_Matrix_Chain(arr));
System.out.println("Minimum number of multiplications is " + memoizedMatrixChain(arr));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ private WineProblem() {

// Method 1: Using Recursion
// Time Complexity=0(2^N) Space Complexity=Recursion extra space
public static int WPRecursion(int[] arr, int si, int ei) {
public static int wpRecursion(int[] arr, int si, int ei) {
int n = arr.length;
int year = (n - (ei - si + 1)) + 1;
if (si == ei) {
return arr[si] * year;
}

int start = WPRecursion(arr, si + 1, ei) + arr[si] * year;
int end = WPRecursion(arr, si, ei - 1) + arr[ei] * year;
int start = wpRecursion(arr, si + 1, ei) + arr[si] * year;
int end = wpRecursion(arr, si, ei - 1) + arr[ei] * year;

return Math.max(start, end);
}

// Method 2: Top-Down DP(Memoization)
// Time Complexity=0(N*N) Space Complexity=0(N*N)+Recursion extra space
public static int WPTD(int[] arr, int si, int ei, int[][] strg) {
public static int wptd(int[] arr, int si, int ei, int[][] strg) {
int n = arr.length;
int year = (n - (ei - si + 1)) + 1;
if (si == ei) {
Expand All @@ -41,8 +41,8 @@ public static int WPTD(int[] arr, int si, int ei, int[][] strg) {
if (strg[si][ei] != 0) {
return strg[si][ei];
}
int start = WPTD(arr, si + 1, ei, strg) + arr[si] * year;
int end = WPTD(arr, si, ei - 1, strg) + arr[ei] * year;
int start = wptd(arr, si + 1, ei, strg) + arr[si] * year;
int end = wptd(arr, si, ei - 1, strg) + arr[ei] * year;

int ans = Math.max(start, end);

Expand All @@ -53,7 +53,7 @@ public static int WPTD(int[] arr, int si, int ei, int[][] strg) {

// Method 3: Bottom-Up DP(Tabulation)
// Time Complexity=0(N*N/2)->0(N*N) Space Complexity=0(N*N)
public static int WPBU(int[] arr) {
public static int wpbu(int[] arr) {
int n = arr.length;
int[][] strg = new int[n][n];

Expand All @@ -76,9 +76,9 @@ public static int WPBU(int[] arr) {

public static void main(String[] args) {
int[] arr = {2, 3, 5, 1, 4};
System.out.println("Method 1: " + WPRecursion(arr, 0, arr.length - 1));
System.out.println("Method 2: " + WPTD(arr, 0, arr.length - 1, new int[arr.length][arr.length]));
System.out.println("Method 3: " + WPBU(arr));
System.out.println("Method 1: " + wpRecursion(arr, 0, arr.length - 1));
System.out.println("Method 2: " + wptd(arr, 0, arr.length - 1, new int[arr.length][arr.length]));
System.out.println("Method 3: " + wpbu(arr));
}
}
// Memoization vs Tabulation : https://www.geeksforgeeks.org/tabulation-vs-memoization/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private SquareRootWithBabylonianMethod() {
* @param num contains elements
* @return the square root of num
*/
public static float square_Root(float num) {
public static float squareRoot(float num) {
float a = num;
float b = 1;
double e = 0.000001;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class TrinomialTriangle {
private TrinomialTriangle() {
}

public static int TrinomialValue(int n, int k) {
public static int trinomialValue(int n, int k) {
if (n == 0 && k == 0) {
return 1;
}
Expand All @@ -20,17 +20,17 @@ public static int TrinomialValue(int n, int k) {
return 0;
}

return (TrinomialValue(n - 1, k - 1) + TrinomialValue(n - 1, k) + TrinomialValue(n - 1, k + 1));
return (trinomialValue(n - 1, k - 1) + trinomialValue(n - 1, k) + trinomialValue(n - 1, k + 1));
}

public static void printTrinomial(int n) {
for (int i = 0; i < n; i++) {
for (int j = -i; j <= 0; j++) {
System.out.print(TrinomialValue(i, j) + " ");
System.out.print(trinomialValue(i, j) + " ");
}

for (int j = 1; j <= i; j++) {
System.out.print(TrinomialValue(i, j) + " ");
System.out.print(trinomialValue(i, j) + " ");
}

System.out.println();
Expand Down
Loading