JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
<< PREV    [ 1 2 ]
Re: Iterating Over All Subsets of a Set (response to post by sjsupersumit) | Reply
It's checking if bit k of i is set, since 1<<k == 2^k.>
Re: Iterating Over All Subsets of a Set (response to post by holomorph) | Reply
How can we extend the idea of to generate subsets with k elements. I can simply iterate over all 1<<n states and counting the number of set bits in each of the subset. If it equals k then I'll take into consideration. Is there any better way of doing this ? Can't we loop over only those sets which have k set bits directly instead of iterating over all 1><<n sets ?
Re: Iterating Over All Subsets of a Set (response to post by d@rk_sh@dow) | Reply
You can either use the method described above in Discussion (for m or less bits). Or you can use a more direct method described in NextBitPermutation here: http://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation
Re: Iterating Over All Subsets of a Set (response to post by dimkadimon) | Reply
the mapping from bit to subset is limited.
when the set size is more than 32 or 64
the subset number will be more than Integer.MIN_VALUE or Long.MAX_VALUE.
Re: Iterating Over All Subsets of a Set (response to post by ZuBruce) | Reply
You can always use a BigInteger. Anyway iterating over such large sets is going to be too slow.
<< PREV    [ 1 2 ]

RSS