- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathSubset_gen.java
24 lines (23 loc) · 787 Bytes
/
Subset_gen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
importjava.util.*;
classSubset_gen// Same as generating all the subsequence of a string
{ // Produces 2^N outputs
staticvoidsubset(Strings, inti, intn, Stringa) // Same thing you have to follow that at a time, u can either choose a character or leave it
{
if (i == n)
{
System.out.println(a);
return;
}
subset(s, i + 1, n, a + s.charAt(i));
subset(s, i + 1, n, a);
}
publicstaticvoidmain(Stringargs[])
{
ScannerI = newScanner(System.in);
System.out.println("ENTER A STRING");
Strings = I.nextLine(); // Considering all characters are distinct
System.out.println();
subset(s, 0, s.length(), "");
I.close();
}
}