Java
Java copied to clipboard
Added ShuffleAlgorithm and various problems related to it.
Shuffle Algorithms for Various Scenarios This PR introduces multiple shuffle algorithms to the com.thealgorithms.shufflealgorithm package, with each class implementing a specific type of shuffle technique. The classes are designed to be flexible for different shuffling scenarios with well-documented methods and edge case handling. Below is a summary of the classes and the shuffle techniques they provide:
- ConstrainedShuffle Purpose: Shuffle the elements in an array while keeping the first and last elements fixed. Method: constrainedShuffle(int[] array) Edge Case Handling: No shuffling occurs if the array has fewer than 3 elements.
- GroupShuffle Purpose: Groups elements into subarrays of a specified size and shuffles those groups. Method: groupShuffle(int[] array, int groupSize) -> List<List<Integer>> Edge Case Handling: Ensures that each group has the specified size (or fewer for the last group) and skips shuffling if groupSize <= 1.
- ShuffleByRange Purpose: Shuffle elements within a specified index range. Method: shuffleByRange(int[] array, int start, int end) Edge Case Handling: Verifies valid indices to avoid IndexOutOfBounds issues.
- UnderstandingShuffleAlgo Purpose: Basic shuffle algorithm that uses a uniform probability approach to randomize array elements. Method: shuffle(int[] array)
- UniquePairShuffle Purpose: Pairs elements randomly without repeating pairs. Method: pairShuffle(int[] array) -> List<int[]> Edge Case Handling: Returns an empty list if the array has an odd length or fewer than 2 elements.
- WeightedShuffle Purpose: Shuffles elements based on their weights, favoring elements with higher weights. Method: weightedShuffle(int[] array, int[] weights) Edge Case Handling: Ensures the weights array matches the array length for proper assignment
Codecov Report
Attention: Patch coverage is 56.31068% with 45 lines in your changes missing coverage. Please review.
Project coverage is 72.29%. Comparing base (
bca8d0e) to head (927e6fd).
Additional details and impacted files
@@ Coverage Diff @@
## master #6053 +/- ##
============================================
- Coverage 72.40% 72.29% -0.11%
- Complexity 4983 5013 +30
============================================
Files 653 659 +6
Lines 17574 17677 +103
Branches 3386 3405 +19
============================================
+ Hits 12724 12780 +56
- Misses 4371 4416 +45
- Partials 479 481 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!
Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!