From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 79665BC75 for ; Fri, 25 Feb 2005 11:56:59 +0100 (CET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.205]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1PAuwbU004613 for ; Fri, 25 Feb 2005 11:56:59 +0100 Received: by rproxy.gmail.com with SMTP id a36so892388rnf for ; Fri, 25 Feb 2005 02:56:58 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=TZILotScuVt1uEQFv5JeCO77VHx1/3lgJpmtJ/F+BLxSI1n/U4s6M7sbr3EyUnNqCApgW5wnt6BNP+0qLgXIndpv7lOaj8L73AgiDaWxwpJlDZlliZWq+kKQj4kywtFT263hb3x+ZmsoD/DdVELnH8zF+kcyyf4Whe2Z4nmf+tQ= Received: by 10.38.97.47 with SMTP id u47mr202715rnb; Fri, 25 Feb 2005 02:56:58 -0800 (PST) Received: by 10.38.65.58 with HTTP; Fri, 25 Feb 2005 02:56:58 -0800 (PST) Message-ID: <7f8e92aa05022502566909d86@mail.gmail.com> Date: Fri, 25 Feb 2005 12:56:58 +0200 From: Radu Grigore Reply-To: Radu Grigore To: Jon Harrop Subject: Re: [Caml-list] Set union Cc: caml-list@yquem.inria.fr In-Reply-To: <200502240920.04902.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <200502240920.04902.jon@jdh30.plus.com> X-Miltered: at nez-perce with ID 421F047A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 ocaml:01 stl:01 ocaml:01 mistaken:01 short:01 tree:02 tree:02 seems:03 root:03 root:03 complex:04 size:95 radu:05 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On Thu, 24 Feb 2005 09:20:04 +0000, Jon Harrop wrote: > > Following my last post about the speed of set union in OCaml compared to > C++/STL. What is the complexity of set union in OCaml in terms of the number > of elements and the number of comparisons? As no one gave an informed answer I'll risk a hand-waiving one. When all elements of a set are bigger than all elements of the other set the Set.union function seems to simply add the elements of the small set to the bigger set one at a time. So the complexity looks like O(m lg n) where m is the size of the smaller set. For other cases the process is a bit more complex: take the root of the short tree, split the large tree into smaller/larger elements based on that root, compute union of "small" trees, "compute union of "large" trees", merge them. If I'm not mistaken this is O(m lg n) too. -- regards, radu http://rgrig.blogspot.com/