English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Set and Map question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-20 (12:41)
From: Igor Pechtchanski <pechtcha@c...>
Subject: Re: [Caml-list] Re: Set and Map question
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.
      |\      _,,,---,,_		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