Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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.
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,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 Archives:
Bug reports: FAQ:
Beginner's list: