-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsetsOfaSet.java
More file actions
43 lines (35 loc) · 937 Bytes
/
subsetsOfaSet.java
File metadata and controls
43 lines (35 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class ubsetsOfaSet {
public static void findSubSet(char[] array ,int n) {
//int n = array.length;
n = (int)Math.pow(2,n);
for(int i=0;i<n;i++) {
String j = Integer.toBinaryString(i);
int z = array.length;
j = binaryHelper(j,z);
//System.out.println(j);
String subSet="";
for(int m=0;m<j.length();m++) {
if(j.charAt(m)=='1')
subSet = subSet + array[m];
}
System.out.println("{"+subSet+"}");
}
}
public static String binaryHelper(String binary , int len) {
if(binary.length()!=len)
{
binary = '0' + binary;
//System.out.println(binary);
binary = binaryHelper(binary , len);
}
return binary;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//char[] set = {'a','b','c','d'};
String s = "abcd";
char[] set = s.toCharArray();
int l =set.length;
findSubSet(set,l);
}
}