We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9e5057b commit e49a414Copy full SHA for e49a414
src/main/java/com/thealgorithms/Recursion/GenerateSubsets.java
@@ -0,0 +1,28 @@
1
+package com.thealgorithms.Recursion;
2
+
3
+// program to find power set of a string
4
5
+import java.util.ArrayList;
6
+import java.util.List;
7
8
+public class GenerateSubsets {
9
10
+ public static List<String> subsetRecursion(String p, String up) {
11
+ if (up.isEmpty()) {
12
+ List<String> list = new ArrayList<>();
13
+ list.add(p);
14
+ return list;
15
+ }
16
17
+ // Taking the character
18
+ char ch = up.charAt(0);
19
+ // Adding the character in the recursion
20
+ List<String> left = subsetRecursion(p + ch, up.substring(1));
21
+ // Not adding the character in the recursion
22
+ List<String> right = subsetRecursion(p, up.substring(1));
23
24
+ left.addAll(right);
25
26
+ return left;
27
28
+}
src/main/java/com/thealgorithms/Recursion/Subsets.java
0 commit comments