Skip to content

Added tree algorithm #5648

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

VarnitRaina
Copy link

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.

@VarnitRaina VarnitRaina marked this pull request as ready for review October 8, 2024 11:19
@siriak
Copy link
Member

siriak commented Oct 9, 2024

Please fix PR checks

Copy link

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 Nov 13, 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 Nov 20, 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.

2 participants