caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: Seth Fogarty <sfogarty@gmail.com>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Re: Set and Map question
Date: Sun, 19 Sep 2004 23:02:44 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0409192258210.5809-100000@localhost.localdomain> (raw)
In-Reply-To: <c7ee6112040919201417b7328@mail.gmail.com>

On Sun, 19 Sep 2004, Seth Fogarty wrote:

> Beh, sorry, I was very confused and asked the wrong questions. The
> answer to the below is yes, as specified in the manual, and I knew
> that. Too many things juggling at once.
> 
> What I MEANT to ask is: Is there a O(n) method of set/map construction
> from a list, as opposed to the O(n log n) fold method.

Implemented?  No.  Possible?  Yes, if the list is sorted.

The code is actually fairly easy.  Take the length of the list.  Subtract 
one for the root node.  The first (n-1)/2 elements are in the left hand 
subtree, the last n-1-((n-1)/2) elements are in the right subtree.

If the list isn't sorted, then no.  Any algorithm for turning the list 
into a sorted tree in less than O(N log N) would also serve for sorting 
the list in less than O(N log N), and would be a major advance in computer 
science.  I don't think it's possible, however.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-09-20  3:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-20  2:37 [Caml-list] " Seth Fogarty
2004-09-20  3:14 ` [Caml-list] " Seth Fogarty
2004-09-20  3:56   ` skaller
2004-09-20  4:18     ` Seth Fogarty
2004-09-20  6:43       ` skaller
2004-09-20  8:32       ` Diego Olivier Fernandez Pons
2004-09-20  4:02   ` Brian Hurt [this message]
2004-09-20  8:17     ` Richard Jones
2004-09-20 12:41       ` Igor Pechtchanski
2004-09-20 12:54         ` Jean-Christophe Filliatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0409192258210.5809-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@pauillac.inria.fr \
    --cc=sfogarty@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).