From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id FAA32214; Mon, 20 Sep 2004 05:52:58 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA31066 for ; Mon, 20 Sep 2004 05:52:57 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8K3qtaf004716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 20 Sep 2004 05:52:56 +0200 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.13.1/8.12.11) with ESMTP id i8K3qYjb007712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 19 Sep 2004 22:52:37 -0500 (CDT) Date: Sun, 19 Sep 2004 23:02:44 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Seth Fogarty cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Re: Set and Map question In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 414E5417.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 implemented:01 sep:01 node:02 tree:02 wrote:03 algorithm:03 redirect:95 meant:05 brian:06 brian:06 source:07 fold:07 root:07 difficult:07 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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