Interview Question

Software Engineer Interview

print all the subsets of set

Answer

Interview Answer

1 Answer

0

on set of size n one can use binary representation of numbers from 0 to 2^n-1, where position of ones will tell you which elements to take. For example on 3 element set:
000 -empty set
001 -first element
010-second element
...
110-second and third element
111-the set itself.

AlexB on Sep 21, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up