Java icon indicating copy to clipboard operation
Java copied to clipboard

Added ShuffleAlgorithm and various problems related to it.

Open Darshan-Baligeri opened this issue 1 year ago • 1 comments

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:

  1. 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.
  2. 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.
  3. 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.
  4. UnderstandingShuffleAlgo Purpose: Basic shuffle algorithm that uses a uniform probability approach to randomize array elements. Method: shuffle(int[] array)
  5. 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.
  6. 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

Darshan-Baligeri avatar Oct 28 '24 15:10 Darshan-Baligeri

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).

Files with missing lines Patch % Lines
.../com/thealgorithms/shufflealgo/ShuffleByRange.java 44.44% 9 Missing and 1 partial :warning:
...gorithms/shufflealgo/UnderstandingShuffleAlgo.java 43.75% 9 Missing :warning:
...va/com/thealgorithms/shufflealgo/GroupShuffle.java 61.11% 7 Missing :warning:
...m/thealgorithms/shufflealgo/UniquePairShuffle.java 58.82% 7 Missing :warning:
...com/thealgorithms/shufflealgo/WeightedShuffle.java 65.00% 7 Missing :warning:
.../thealgorithms/shufflealgo/ConstrainedShuffle.java 64.28% 5 Missing :warning:
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.

codecov-commenter avatar Oct 28 '24 15:10 codecov-commenter

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!

github-actions[bot] avatar Dec 03 '24 00:12 github-actions[bot]

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!

github-actions[bot] avatar Dec 13 '24 00:12 github-actions[bot]