Added tree algorithm
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.
Please fix PR checks
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!