Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces a new algorithm to generate all unique permutations of a given string, even when the string contains duplicate characters. The algorithm is implemented in the UniquePermutations class under the package com.thealgorithms.Recursion.
Key Features:
Algorithm Implementation:
The method getUniquePermutations(String str) generates all unique permutations of the input string.
The algorithm sorts the characters of the string to handle duplicate characters effectively.
It employs a backtracking approach to explore all possible arrangements of the characters.
Edge Case Handling:
The algorithm accounts for various edge cases such as:
Null Input: Returns an empty list.
Empty String: Returns a list containing an empty string as the only permutation.
Single Character: Returns a list containing the single character as the only permutation.
Identical Characters: Returns a list with one entry for strings composed of identical characters.
Test Cases:
Comprehensive test cases have been added to ensure the functionality and correctness of the algorithm. These test cases are located in the UniquePermutationsTest class and include:
Basic Tests: Validate the algorithm with simple strings like "abc".
Duplicate Characters: Check handling of duplicates with strings like "aab".
Edge Cases: Confirm behavior for empty strings, single characters, and strings with identical characters.
Mixed Case: Ensure the algorithm correctly handles mixed case strings like "aAb".
Null Input: Verify that null input results in an empty list.
Reference
For a simpler version of this algorithm, you can refer to this GeeksforGeeks article.