Skip to content

feat : new recursion algos TowerOfHanoi.java and GenerateUniqueSubsets.java added #5581

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
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
37bb532
LinkedList added
Tuhinm2002 Oct 1, 2024
17d0ca3
LinkedList added
Tuhinm2002 Oct 1, 2024
ee3cacb
feat: recursion subsets added
Tuhinm2002 Oct 1, 2024
9e5057b
Update and rename SubsetsTest.java to GenerateSubsetsTest.java
Tuhinm2002 Oct 2, 2024
e49a414
Update and rename Subsets.java to GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
89687c8
Update GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
eceb162
Update GenerateSubsetsTest.java
Tuhinm2002 Oct 2, 2024
6d840a2
Update GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
5043123
Update GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
61a81c9
Update GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
d3d154e
Update GenerateSubsetsTest.java
Tuhinm2002 Oct 2, 2024
25874a9
Update GenerateSubsets.java
Tuhinm2002 Oct 2, 2024
ba81599
Update GenerateSubsetsTest.java
Tuhinm2002 Oct 2, 2024
c14d684
Merge branch 'master' into master
Tuhinm2002 Oct 2, 2024
0d202a6
Merge branch 'master' into master
siriak Oct 2, 2024
b11a6be
Merge branch 'TheAlgorithms:master' into master
Tuhinm2002 Oct 2, 2024
b3c0ee6
feat: new recursion algo added
Tuhinm2002 Oct 3, 2024
4775400
Merge branch 'TheAlgorithms:master' into master
Tuhinm2002 Oct 3, 2024
316ae83
Update GenerateSubsets.java
Tuhinm2002 Oct 3, 2024
3722690
Update GenerateUniqueSubsetsTest.java
Tuhinm2002 Oct 3, 2024
a3e34f7
Update TowerOfHanoiTest.java
Tuhinm2002 Oct 3, 2024
283f35b
Update GenerateUniqueSubsets.java
Tuhinm2002 Oct 3, 2024
09fba41
Merge branch 'master' into master
Tuhinm2002 Oct 4, 2024
68a7efe
Merge branch 'master' into master
Tuhinm2002 Oct 4, 2024
1b0c0b8
Merge branch 'master' into master
Tuhinm2002 Oct 4, 2024
52715aa
Merge branch 'master' into master
Tuhinm2002 Oct 5, 2024
bebf28d
Delete src/main/java/com/thealgorithms/ciphers/DES.java
Tuhinm2002 Oct 5, 2024
99a2e40
Delete src/main/java/com/thealgorithms/datastructures/crdt/GSet.java
Tuhinm2002 Oct 5, 2024
6478452
Delete src/main/java/com/thealgorithms/dynamicprogramming/SubsetSum.java
Tuhinm2002 Oct 5, 2024
127703e
Delete src/main/java/com/thealgorithms/dynamicprogramming/MinimumSumP…
Tuhinm2002 Oct 5, 2024
33e3018
Delete src/main/java/com/thealgorithms/dynamicprogramming/PartitionPr…
Tuhinm2002 Oct 5, 2024
dab10c6
Delete src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount…
Tuhinm2002 Oct 5, 2024
063b472
Delete src/main/java/com/thealgorithms/datastructures/graphs/BoruvkaA…
Tuhinm2002 Oct 5, 2024
c4e5e18
Delete src/main/java/com/thealgorithms/datastructures/crdt/LWWElement…
Tuhinm2002 Oct 5, 2024
8de38cb
Delete src/main/java/com/thealgorithms/datastructures/crdt/TwoPSet.java
Tuhinm2002 Oct 5, 2024
09638b5
Delete src/main/java/com/thealgorithms/datastructures/crdt/ORSet.java
Tuhinm2002 Oct 5, 2024
3b3b1db
Merge branch 'master' into master
Tuhinm2002 Oct 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import java.util.ArrayList;
import java.util.List;

/**
* Finds all permutations of given array
* @author Tuhin Mondal (<a href="https://github.com/tuhinm2002">Git-Tuhin Mondal</a>)
*/

public final class GenerateSubsets {

private GenerateSubsets() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.thealgorithms.Recursion;

// program to find unique power set of a string

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Finds all permutations of given array
* @author Tuhin Mondal (<a href="https://github.com/tuhinm2002">Git-Tuhin Mondal</a>)
*/

public final class GenerateUniqueSubsets {

private GenerateUniqueSubsets() {
throw new UnsupportedOperationException("Utility class");
}

public static List<String> subsetRecursion(String str) {
Set<String> ans = doRecursion("", str);
List<String> a = new ArrayList<>(ans.stream().toList());
Collections.sort(a);
return a;
}

private static Set<String> doRecursion(String p, String up) {
if (up.isEmpty()) {
Set<String> list = new HashSet<>();
list.add(p);
return list;
}

// Taking the character
char ch = up.charAt(0);
// Adding the character in the recursion
Set<String> left = doRecursion(p + ch, up.substring(1));
// Not adding the character in the recursion
Set<String> right = doRecursion(p, up.substring(1));

left.addAll(right);

return left;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/thealgorithms/Recursion/TowerOfHanoi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.thealgorithms.Recursion;

import java.util.ArrayList;
import java.util.List;

/**
* Finds all permutations of given array
* @author Tuhin Mondal (<a href="https://github.com/tuhinm2002">Git-Tuhin Mondal</a>)
*/

public final class TowerOfHanoi {
private TowerOfHanoi() {
throw new UnsupportedOperationException("Utility class");
}

public static List<String> towerOfHanoi(int n) {
List<String> arr = new ArrayList<>();
recursionApproach(n, 'A', 'B', 'C', arr);
return arr;
}

public static void recursionApproach(int n, char a, char b, char c, List<String> list) {
if (n == 1) {
list.add("Take disk 1 from rod " + a + " to rod " + b);
return;
}

recursionApproach(n - 1, a, c, b, list);
list.add("Take disk " + n + " from rod " + a + " to rod " + b);
recursionApproach(n - 1, c, b, a, list);
}
}
250 changes: 0 additions & 250 deletions src/main/java/com/thealgorithms/ciphers/DES.java

This file was deleted.

Loading
Loading