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 (03:52)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Re: Set and Map question
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 

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: