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

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

```