Skip to content

Commit e49a414

Browse files
authored
Update and rename Subsets.java to GenerateSubsets.java
1 parent 9e5057b commit e49a414

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)