Skip to content
Closed
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
8 changes: 2 additions & 6 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
- 📄 [FirstDifferentBit](src/main/java/com/thealgorithms/bitmanipulation/FirstDifferentBit.java)
- 📄 [GenerateSubsets](src/main/java/com/thealgorithms/bitmanipulation/GenerateSubsets.java)
- 📄 [GrayCodeConversion](src/main/java/com/thealgorithms/bitmanipulation/GrayCodeConversion.java)
- 📄 [HammingDistance](src/main/java/com/thealgorithms/bitmanipulation/HammingDistance.java)
- 📄 [HigherLowerPowerOfTwo](src/main/java/com/thealgorithms/bitmanipulation/HigherLowerPowerOfTwo.java)
- 📄 [HighestSetBit](src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java)
- 📄 [IndexOfRightMostSetBit](src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java)
Expand Down Expand Up @@ -346,7 +345,6 @@
- 📄 [LongestIncreasingSubsequence](src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java)
- 📄 [LongestIncreasingSubsequenceNLogN](src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceNLogN.java)
- 📄 [LongestPalindromicSubsequence](src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubsequence.java)
- 📄 [LongestPalindromicSubstring](src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java)
- 📄 [LongestValidParentheses](src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java)
- 📄 [MatrixChainMultiplication](src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainMultiplication.java)
- 📄 [MatrixChainRecursiveTopDownMemoisation](src/main/java/com/thealgorithms/dynamicprogramming/MatrixChainRecursiveTopDownMemoisation.java)
Expand Down Expand Up @@ -406,7 +404,7 @@
- 📄 [ActivitySelection](src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java)
- 📄 [BandwidthAllocation](src/main/java/com/thealgorithms/greedyalgorithms/BandwidthAllocation.java)
- 📄 [BinaryAddition](src/main/java/com/thealgorithms/greedyalgorithms/BinaryAddition.java)
- 📄 [CoinChange](src/main/java/com/thealgorithms/greedyalgorithms/CoinChange.java)
- 📄 [GreedyCoinChange](src/main/java/com/thealgorithms/greedyalgorithms/GreedyCoinChange.java)
- 📄 [DigitSeparation](src/main/java/com/thealgorithms/greedyalgorithms/DigitSeparation.java)
- 📄 [EgyptianFraction](src/main/java/com/thealgorithms/greedyalgorithms/EgyptianFraction.java)
- 📄 [FractionalKnapsack](src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java)
Expand Down Expand Up @@ -595,7 +593,7 @@
- 📄 [ArrayRightRotation](src/main/java/com/thealgorithms/others/ArrayRightRotation.java)
- 📄 [BFPRT](src/main/java/com/thealgorithms/others/BFPRT.java)
- 📄 [BankersAlgorithm](src/main/java/com/thealgorithms/others/BankersAlgorithm.java)
- 📄 [BoyerMoore](src/main/java/com/thealgorithms/others/BoyerMoore.java)
- 📄 [BoyerMooreMajorityVote](src/main/java/com/thealgorithms/others/BoyerMooreMajorityVote.java)
- 📄 [BrianKernighanAlgorithm](src/main/java/com/thealgorithms/others/BrianKernighanAlgorithm.java)
- 📄 [CRC16](src/main/java/com/thealgorithms/others/CRC16.java)
- 📄 [CRC32](src/main/java/com/thealgorithms/others/CRC32.java)
Expand Down Expand Up @@ -627,7 +625,6 @@
- 📄 [TwoPointers](src/main/java/com/thealgorithms/others/TwoPointers.java)
- 📄 [Verhoeff](src/main/java/com/thealgorithms/others/Verhoeff.java)
- 📁 **cn**
- 📄 [HammingDistance](src/main/java/com/thealgorithms/others/cn/HammingDistance.java)
- 📁 **physics**
- 📄 [CoulombsLaw](src/main/java/com/thealgorithms/physics/CoulombsLaw.java)
- 📄 [DampedOscillator](src/main/java/com/thealgorithms/physics/DampedOscillator.java)
Expand Down Expand Up @@ -834,7 +831,6 @@
- 📄 [StringMatchFiniteAutomata](src/main/java/com/thealgorithms/strings/StringMatchFiniteAutomata.java)
- 📄 [SuffixArray](src/main/java/com/thealgorithms/strings/SuffixArray.java)
- 📄 [Upper](src/main/java/com/thealgorithms/strings/Upper.java)
- 📄 [ValidParentheses](src/main/java/com/thealgorithms/strings/ValidParentheses.java)
- 📄 [WordLadder](src/main/java/com/thealgorithms/strings/WordLadder.java)
- 📄 [ZAlgorithm](src/main/java/com/thealgorithms/strings/ZAlgorithm.java)
- 📁 **zigZagPattern**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.thealgorithms.greedyalgorithms;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

/**
* Greedy coin change (renamed for clarity).
*
* <p>Resolves naming conflict: "CoinChange" exists in both dynamicprogramming (DP: count combinations,
* minimum coins) and greedyalgorithms. This class is the greedy approach using fixed denominations.
*
* <p>Returns a list of coins that sum to the given amount using a greedy strategy with
* standard denominations (1, 2, 5, 10, 20, 50, 100, 500, 2000).
*
* @see <a href="https://en.wikipedia.org/wiki/Change-making_problem">Change-making problem</a>
*/
public final class GreedyCoinChange {
private GreedyCoinChange() {
}

/**
* Returns a list of coins (in descending order of use) that sum to the given amount.
* Uses greedy selection with fixed denominations.
*
* @param amount the target amount
* @return list of coin values that sum to amount (may be empty if amount is 0)
*/
public static ArrayList<Integer> coinChangeProblem(int amount) {
Integer[] coins = {1, 2, 5, 10, 20, 50, 100, 500, 2000};
Arrays.sort(coins, Comparator.reverseOrder());

ArrayList<Integer> ans = new ArrayList<>();

for (Integer coin : coins) {
while (coin <= amount) {
ans.add(coin);
amount -= coin;
}
}
return ans;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.thealgorithms.others;

import java.util.Optional;

/**
* Utility class implementing Boyer-Moore's Voting Algorithm to find the majority element
* in an array. The majority element is defined as the element that appears more than n/2 times
* in the array, where n is the length of the array.
* Boyer-Moore Majority Vote Algorithm (renamed for clarity).
*
* <p>Resolves naming conflict: "BoyerMoore" in others referred to the majority vote algorithm,
* while searches.BoyerMoore is the string-search algorithm. This class is the majority-vote implementation.
*
* For more information on the algorithm, refer to:
* https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
* <p>Finds the majority element in an array (element that appears more than n/2 times).
*
* @see <a href="https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm">Boyer–Moore majority vote algorithm</a>
*/
public final class BoyerMoore {
private BoyerMoore() {
public final class BoyerMooreMajorityVote {
private BoyerMooreMajorityVote() {
}

/**
Expand All @@ -33,12 +36,6 @@ public static Optional<Integer> findMajorityElement(int[] array) {
return Optional.empty();
}

/**
* Identifies the potential majority candidate using Boyer-Moore's Voting Algorithm.
*
* @param array the input array
* @return the candidate for the majority element
*/
private static int findCandidate(final int[] array) {
int count = 0;
int candidate = -1;
Expand All @@ -51,13 +48,6 @@ private static int findCandidate(final int[] array) {
return candidate;
}

/**
* Counts the occurrences of the candidate element in the array.
*
* @param candidate the candidate element
* @param array the input array
* @return the number of times the candidate appears in the array
*/
private static int countOccurrences(final int candidate, final int[] array) {
int count = 0;
for (int value : array) {
Expand All @@ -68,13 +58,6 @@ private static int countOccurrences(final int candidate, final int[] array) {
return count;
}

/**
* Determines if the count of the candidate element is more than n/2, where n is the length of the array.
*
* @param count the number of occurrences of the candidate
* @param totalCount the total number of elements in the array
* @return true if the candidate is the majority element, false otherwise
*/
private static boolean isMajority(int count, int totalCount) {
return 2 * count > totalCount;
}
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/com/thealgorithms/others/cn/HammingDistance.java

This file was deleted.

Loading
Loading