Anonymous user
Power set: Difference between revisions
→Non-recursive version: improved the descriptions of my algorithm
(→{{header|R}}: added non-recursive method that is 100x faster) |
(→Non-recursive version: improved the descriptions of my algorithm) |
||
Line 1,704:
</lang>
<lang R>powerset = function(set){
Line 1,723 ⟶ 1,721:
powerset(1:4)
</lang>
The list "temp" is a compromise between the speed costs of doing arithmetic and of creating new lists (since R lists are immutable, appending to a list means actually creating a new list object). Thus, "temp" collects new subsets that are later added to the power set. This improves the speed by 4x compared to extending the list "ps" at every step.
===Recursive version===
|