-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathallSubsets.java
More file actions
34 lines (30 loc) · 884 Bytes
/
allSubsets.java
File metadata and controls
34 lines (30 loc) · 884 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
import java.io.IOException;
import java.math.BigInteger;
class allSubsets
{
static void printSubsets(char set[])
{
int n = set.length;
for (int i = 0; i < (1<<n); i++)
{
System.out.print("{ ");
for (int j = 0; j < n; j++)
{
// if ((i & (1 << j)) > 0)
// System.out.print(set[j] + " ");
if (BigInteger.valueOf(i).testBit(j))
System.out.print(set[j]+" ");
}
System.out.println("}");
}
}
public static void main(String[] args)
{
char set[] = {'a', 'b', 'c','d'};
printSubsets(set);
}
}
// 1<<3
// 1000=8
//basically if left shift add zeros by which times the shift we have to do
//in case of right shift remove that or basically shift towards right