Skip to content

Added ShuffleAlgorithm and various problems related to it. #6053

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

Closed

Conversation

Darshan-Baligeri
Copy link

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

@codecov-commenter
Copy link

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 ⚠️
...gorithms/shufflealgo/UnderstandingShuffleAlgo.java 43.75% 9 Missing ⚠️
...va/com/thealgorithms/shufflealgo/GroupShuffle.java 61.11% 7 Missing ⚠️
...m/thealgorithms/shufflealgo/UniquePairShuffle.java 58.82% 7 Missing ⚠️
...com/thealgorithms/shufflealgo/WeightedShuffle.java 65.00% 7 Missing ⚠️
.../thealgorithms/shufflealgo/ConstrainedShuffle.java 64.28% 5 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix PR checks

Copy link

github-actions bot commented Dec 3, 2024

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 github-actions bot added the stale label Dec 3, 2024
Copy link

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 github-actions bot closed this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants