Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Subsets of a list
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John David Stone  
View profile  
 More options Jan 11 2002, 1:12 pm
Newsgroups: comp.lang.scheme
From: John David Stone <st...@cs.grinnell.edu>
Date: 11 Jan 2002 12:12:36 -0600
Local: Fri, Jan 11 2002 1:12 pm
Subject: Re: Subsets of a list

George Caswell <tetsu...@maine.rr.com> writes:
>    Anyway, my implementation, "subs" uses up a lot of heap space compared to,
> say, "combos" posted by John Stone, and incurs more garbage collection, but
> still comes out faster:

> (define (expand xs sets)
>     (if (or (null? xs) (null? sets))
>         ()
>    (cons
>        (apply append (map (lambda (set) (map (lambda (s) (cons (car xs)
> s)) set)) (cdr sets)))
>        (expand (cdr xs) (cdr sets)))
> ))

> (define (subs xs n)
>     (cond ((eq? 0 n) ())
>         (else
>        (do ((i 1 (+ i 1))
>             (acc (map (lambda (x) (list (list x))) xs) (expand xs acc)))
>            ((= i n) (apply append acc))))))

        I used SUBS to find all the ten-element subsets of a twenty-element
set, in the same environment (Chez Scheme 6.1, Linux, 700MHz Pentium III)
where SUBSETS took 460 ms and COMBOS took 250 ms for the same task.  SUBS
took 990 ms.

--
   John David Stone - Lecturer in Computer Science and Philosophy
           Manager of the Mathematics Local-Area Network
           Grinnell College - Grinnell, Iowa 50112 - USA
     st...@cs.grinnell.edu - http://www.cs.grinnell.edu/~stone/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.