style: enable MethodName in CheckStyle (#5182)

enabled: MethodName in CheckStyle
This commit is contained in:
Godwill Christopher
2024-05-27 01:06:06 -06:00
committed by GitHub
parent ea4dc15a24
commit 295e7436b1
53 changed files with 225 additions and 225 deletions

View File

@ -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++;
@ -26,7 +26,7 @@ public class PowerSum {
// 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);
@ -34,7 +34,7 @@ public class PowerSum {
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);
}
}

View File

@ -106,7 +106,7 @@ public class DES {
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();
@ -143,7 +143,7 @@ public class DES {
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
@ -175,7 +175,7 @@ public class DES {
// 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;
}

View File

@ -91,7 +91,7 @@ public class LeftistHeap {
}
// 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;
@ -101,17 +101,17 @@ public class LeftistHeap {
}
// 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);
}
}

View File

@ -25,10 +25,10 @@ public class GenericTree {
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");
@ -41,7 +41,7 @@ public class GenericTree {
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;
@ -51,17 +51,17 @@ public class GenericTree {
* 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));
}
}

View File

@ -8,7 +8,7 @@ final class 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();
@ -17,7 +17,7 @@ final class NearestRightKey {
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);

View File

@ -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) {

View File

@ -16,7 +16,7 @@ public final class 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
@ -68,6 +68,6 @@ public final class LongestAlternatingSubsequence {
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));
}
}

View File

@ -20,7 +20,7 @@ public final class LongestIncreasingSubsequence {
return r;
}
public static int LIS(int[] array) {
public static int lis(int[] array) {
int N = array.length;
if (N == 0) {
return 0;

View File

@ -12,14 +12,14 @@ public final class LongestPalindromicSubsequence {
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());

View File

@ -11,14 +11,14 @@ public final class LongestPalindromicSubstring {
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;
}

View File

@ -10,7 +10,7 @@ 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++) {
@ -18,10 +18,10 @@ public final class MatrixChainRecursiveTopDownMemoisation {
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];
@ -30,7 +30,7 @@ public final class MatrixChainRecursiveTopDownMemoisation {
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;
}
@ -43,6 +43,6 @@ public final class MatrixChainRecursiveTopDownMemoisation {
// 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));
}
}

View File

@ -16,22 +16,22 @@ public final class 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) {
@ -41,8 +41,8 @@ public final class WineProblem {
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);
@ -53,7 +53,7 @@ public final class WineProblem {
// 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];
@ -76,9 +76,9 @@ public final class WineProblem {
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/

View File

@ -10,7 +10,7 @@ public final class 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;

View File

@ -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;
}
@ -20,17 +20,17 @@ public final class TrinomialTriangle {
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();

View File

@ -24,13 +24,13 @@ public class ThreeSumProblem {
arr[i] = scan.nextInt();
}
ThreeSumProblem th = new ThreeSumProblem();
System.out.println("Brute Force Approach\n" + (th.BruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.TwoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.Hashmap(arr, ts)));
System.out.println("Brute Force Approach\n" + (th.bruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.twoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.hashMap(arr, ts)));
scan.close();
}
public List<List<Integer>> BruteForce(int[] nums, int target) {
public List<List<Integer>> bruteForce(int[] nums, int target) {
List<List<Integer>> arr = new ArrayList<List<Integer>>();
for (int i = 0; i < nums.length; i++) {
@ -51,7 +51,7 @@ public class ThreeSumProblem {
return arr;
}
public List<List<Integer>> TwoPointer(int[] nums, int target) {
public List<List<Integer>> twoPointer(int[] nums, int target) {
Arrays.sort(nums);
List<List<Integer>> arr = new ArrayList<List<Integer>>();
int start = 0;
@ -81,7 +81,7 @@ public class ThreeSumProblem {
return new ArrayList<List<Integer>>(set);
}
public List<List<Integer>> Hashmap(int[] nums, int target) {
public List<List<Integer>> hashMap(int[] nums, int target) {
Arrays.sort(nums);
Set<List<Integer>> ts = new HashSet<>();
HashMap<Integer, Integer> hm = new HashMap<>();

View File

@ -11,7 +11,7 @@ public final class CountChar {
* @return number of character in the specified string
*/
public static int CountCharacters(String str) {
public static int countCharacters(String str) {
return str.replaceAll("\\s", "").length();
}
}

View File

@ -13,11 +13,11 @@ public final class KMP {
public static void main(String[] args) {
final String haystack = "AAAAABAAABA"; // This is the full string
final String needle = "AAAA"; // This is the substring that we want to find
KMPmatcher(haystack, needle);
kmpMatcher(haystack, needle);
}
// find the starting index in string haystack[] that matches the search word P[]
public static void KMPmatcher(final String haystack, final String needle) {
public static void kmpMatcher(final String haystack, final String needle) {
final int m = haystack.length();
final int n = needle.length();
final int[] pi = computePrefixFunction(needle);

View File

@ -33,7 +33,7 @@ public final class KochSnowflake {
ArrayList<Vector2> vectors = new ArrayList<Vector2>();
vectors.add(new Vector2(0, 0));
vectors.add(new Vector2(1, 0));
ArrayList<Vector2> result = Iterate(vectors, 1);
ArrayList<Vector2> result = iterate(vectors, 1);
assert result.get(0).x == 0;
assert result.get(0).y == 0;
@ -54,7 +54,7 @@ public final class KochSnowflake {
int imageWidth = 600;
double offsetX = imageWidth / 10.;
double offsetY = imageWidth / 3.7;
BufferedImage image = GetKochSnowflake(imageWidth, 5);
BufferedImage image = getKochSnowflake(imageWidth, 5);
// The background should be white
assert image.getRGB(0, 0) == new Color(255, 255, 255).getRGB();
@ -80,10 +80,10 @@ public final class KochSnowflake {
* @param steps The number of iterations.
* @return The transformed vectors after the iteration-steps.
*/
public static ArrayList<Vector2> Iterate(ArrayList<Vector2> initialVectors, int steps) {
public static ArrayList<Vector2> iterate(ArrayList<Vector2> initialVectors, int steps) {
ArrayList<Vector2> vectors = initialVectors;
for (int i = 0; i < steps; i++) {
vectors = IterationStep(vectors);
vectors = iterationStep(vectors);
}
return vectors;
@ -96,7 +96,7 @@ public final class KochSnowflake {
* @param steps The number of iterations.
* @return The image of the rendered Koch snowflake.
*/
public static BufferedImage GetKochSnowflake(int imageWidth, int steps) {
public static BufferedImage getKochSnowflake(int imageWidth, int steps) {
if (imageWidth <= 0) {
throw new IllegalArgumentException("imageWidth should be greater than zero");
}
@ -111,8 +111,8 @@ public final class KochSnowflake {
initialVectors.add(vector2);
initialVectors.add(vector3);
initialVectors.add(vector1);
ArrayList<Vector2> vectors = Iterate(initialVectors, steps);
return GetImage(vectors, imageWidth, imageWidth);
ArrayList<Vector2> vectors = iterate(initialVectors, steps);
return getImage(vectors, imageWidth, imageWidth);
}
/**
@ -125,7 +125,7 @@ public final class KochSnowflake {
* applied.
* @return The transformed vectors after the iteration-step.
*/
private static ArrayList<Vector2> IterationStep(ArrayList<Vector2> vectors) {
private static ArrayList<Vector2> iterationStep(ArrayList<Vector2> vectors) {
ArrayList<Vector2> newVectors = new ArrayList<Vector2>();
for (int i = 0; i < vectors.size() - 1; i++) {
Vector2 startVector = vectors.get(i);
@ -149,7 +149,7 @@ public final class KochSnowflake {
* @param imageHeight The height of the rendered image.
* @return The image of the rendered edges.
*/
private static BufferedImage GetImage(ArrayList<Vector2> vectors, int imageWidth, int imageHeight) {
private static BufferedImage getImage(ArrayList<Vector2> vectors, int imageWidth, int imageHeight) {
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();

View File

@ -20,7 +20,7 @@ public final class LineSweep {
* param = ranges : Array of range[start,end]
* return Maximum Endpoint
*/
public static int FindMaximumEndPoint(int[][] ranges) {
public static int findMaximumEndPoint(int[][] ranges) {
Arrays.sort(ranges, Comparator.comparingInt(a -> a[1]));
return ranges[ranges.length - 1][1];
}
@ -32,7 +32,7 @@ public final class LineSweep {
*/
public static boolean isOverlap(int[][] ranges) {
int maximumEndPoint = FindMaximumEndPoint(ranges);
int maximumEndPoint = findMaximumEndPoint(ranges);
Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));
int[] numberLine = new int[maximumEndPoint + 2];
for (int[] range : ranges) {

View File

@ -12,7 +12,7 @@ public final class BinarySearch2dArray {
private BinarySearch2dArray() {
}
static int[] BinarySearch(int[][] arr, int target) {
static int[] binarySearch(int[][] arr, int target) {
int rowCount = arr.length;
int colCount = arr[0].length;

View File

@ -2,7 +2,7 @@ package com.thealgorithms.searches;
class KMPSearch {
int KMPSearch(String pat, String txt) {
int kmpSearch(String pat, String txt) {
int M = pat.length();
int N = txt.length();

View File

@ -15,7 +15,7 @@ public final class OrderAgnosticBinarySearch {
private OrderAgnosticBinarySearch() {
}
static int BinSearchAlgo(int[] arr, int start, int end, int target) {
static int binSearchAlgo(int[] arr, int start, int end, int target) {
// Checking whether the given array is ascending order
boolean AscOrd = arr[start] < arr[end];

View File

@ -13,14 +13,14 @@ public class DutchNationalFlagSort implements SortAlgorithm {
@Override
public <T extends Comparable<T>> T[] sort(T[] unsorted) {
return dutch_national_flag_sort(unsorted, unsorted[(int) Math.ceil((unsorted.length) / 2.0) - 1]);
return dutchNationalFlagSort(unsorted, unsorted[(int) Math.ceil((unsorted.length) / 2.0) - 1]);
}
public <T extends Comparable<T>> T[] sort(T[] unsorted, T intendedMiddle) {
return dutch_national_flag_sort(unsorted, intendedMiddle);
return dutchNationalFlagSort(unsorted, intendedMiddle);
}
private <T extends Comparable<T>> T[] dutch_national_flag_sort(T[] arr, T intendedMiddle) {
private <T extends Comparable<T>> T[] dutchNationalFlagSort(T[] arr, T intendedMiddle) {
int i = 0;
int j = 0;
int k = arr.length - 1;

View File

@ -10,21 +10,21 @@ public final class MergeSortNoExtraSpace {
private MergeSortNoExtraSpace() {
}
public static void call_merge_sort(int[] a, int n) {
public static void callMergeSort(int[] a, int n) {
int maxele = Arrays.stream(a).max().getAsInt() + 1;
merge_sort(a, 0, n - 1, maxele);
mergeSort(a, 0, n - 1, maxele);
}
public static void merge_sort(int[] a, int start, int end, int maxele) { // this function divides the array into 2 halves
public static void mergeSort(int[] a, int start, int end, int maxele) { // this function divides the array into 2 halves
if (start < end) {
int mid = (start + end) / 2;
merge_sort(a, start, mid, maxele);
merge_sort(a, mid + 1, end, maxele);
implement_merge_sort(a, start, mid, end, maxele);
mergeSort(a, start, mid, maxele);
mergeSort(a, mid + 1, end, maxele);
implementMergeSort(a, start, mid, end, maxele);
}
}
public static void implement_merge_sort(int[] a, int start, int mid, int end,
public static void implementMergeSort(int[] a, int start, int mid, int end,
int maxele) { // implementation of mergesort
int i = start;
int j = mid + 1;
@ -64,7 +64,7 @@ public final class MergeSortNoExtraSpace {
for (int i = 0; i < n; i++) {
a[i] = inp.nextInt();
}
call_merge_sort(a, n);
callMergeSort(a, n);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}