-
Notifications
You must be signed in to change notification settings - Fork 19.9k
added shuffle algorithm, it's implementation and problems related to it #6030
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6030 +/- ##
============================================
- Coverage 72.37% 72.36% -0.02%
- Complexity 4981 5013 +32
============================================
Files 652 658 +6
Lines 17569 17663 +94
Branches 3385 3403 +18
============================================
+ Hits 12716 12781 +65
- Misses 4373 4398 +25
- Partials 480 484 +4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove main functions and add JUnit tests
Pull Request Description
Overview
This pull request adds multiple shuffle algorithms to the repository, each accompanied by its implementation and distinct problems that demonstrate its use. The following algorithms have been included:
Unique Pair Shuffle: This algorithm randomly creates pairs from elements in an array while avoiding duplicate pairings. If the input array has an odd number of elements, it returns an empty result.
Group Shuffle: This function splits an array into a defined number of groups and shuffles the contents of each group independently. It also addresses scenarios where the requested number of groups is greater than the length of the array.
Shuffle by Range: This method allows for shuffling a specific section of an array while leaving elements outside that range unchanged. It includes checks to verify that the specified start and end indices are valid.
Weighted Shuffle: This algorithm shuffles an array based on the assigned weights of its elements, ensuring that elements with higher weights are more likely to appear earlier in the shuffled output.
Constrained Shuffling: This technique rearranges an array so that no element remains in its original position. It features validation to confirm that this requirement is satisfied.
Implementation Details
Each algorithm has been developed with a focus on handling edge cases and validating inputs effectively.
In-depth inline documentation is provided to enhance understanding and usability, making the code accessible to beginners.
Unique problems associated with each algorithm have been crafted to broaden the practical applications of the shuffling methods.
Testing
All algorithms have undergone rigorous testing with a variety of inputs to verify their functionality, including edge cases like empty arrays, single-element arrays, and invalid inputs.
Conclusion
These contributions enrich the algorithm library by introducing new, practical algorithms along with relevant problems, fostering further exploration and application in shuffle-related tasks.