caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Igor Pechtchanski <pechtcha@cs.nyu.edu>
To: Richard Jones <rich@annexia.org>
Cc: Brian Hurt <bhurt@spnz.org>, caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Re: Set and Map question
Date: Mon, 20 Sep 2004 08:41:26 -0400 (EDT)	[thread overview]
Message-ID: <Pine.GSO.4.61.0409200836210.12686@slinky.cs.nyu.edu> (raw)
In-Reply-To: <20040920081708.GA2792@annexia.org>

On Mon, 20 Sep 2004, Richard Jones wrote:

> On Sun, Sep 19, 2004 at 11:02:44PM -0500, Brian Hurt wrote:
> > 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.
>
> Wouldn't you have to iterate over the list when implementing this?
> What I mean to say is that this would work if you had a pre-sorted
> Array, but not a linked List.  ?

Did the question mention anything about the space used by the algorithm?
If one is allowed O(n) temp space, then simply converting the sorted
linked List into a temp array as the first step will keep the algorithm
O(n) (constant factors aside).  One would need a constant-time-access data
structure anyway, to build a balanced tree bottom-up in a functional way.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

-------------------
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


  reply	other threads:[~2004-09-20 12:41 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
2004-09-20  8:17     ` Richard Jones
2004-09-20 12:41       ` Igor Pechtchanski [this message]
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.GSO.4.61.0409200836210.12686@slinky.cs.nyu.edu \
    --to=pechtcha@cs.nyu.edu \
    --cc=bhurt@spnz.org \
    --cc=caml-list@pauillac.inria.fr \
    --cc=rich@annexia.org \
    /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).