New course! Every coder should learn Generative AI!
Try a free lesson0
I want to get all the possible subsets for a given array
N is length and 2^n is list
2 Answers
+ 9
You can make use of binary numbers for it, try writing down binary numbers starting from 0 to 2^n-1 & use that sequence to form subsets.
example: subsets for {a, b} :
0 -> 00 -> {}
1 -> 01 -> {b}
2 -> 10 -> {a}
2^2 -1=3 -> 11 -> {a, b}
you can take 1 means elements present & 0 means element is not present.
+ 1
Super.... thanks a lot