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 SAA31330; Sat, 7 Dec 2002 18:32:03 +0100 (MET) 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 SAA31846 for ; Sat, 7 Dec 2002 18:32:02 +0100 (MET) Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gB7HW0120920; Sat, 7 Dec 2002 18:32:01 +0100 (MET) Received: from tw304h3 oleg_inconnu@smtp-send.myrealbox.com [156.111.84.180] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 3.21 $ on Novell NetWare via secured & encrypted transport (TLS); Sat, 07 Dec 2002 10:31:58 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Oleg To: Xavier Leroy , Issac Trotts Subject: Re: [Caml-list] function Date: Sat, 7 Dec 2002 12:31:33 -0500 User-Agent: KMail/1.4.3 Cc: OCaml Mailing List References: <20021203232211.GC22545@beech> <20021206213120.GC696@boson.ucdavis.edu> <20021207112814.A23052@pauillac.inria.fr> In-Reply-To: <20021207112814.A23052@pauillac.inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200212071231.33590.oleg_inconnu@myrealbox.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Saturday 07 December 2002 05:28 am, Xavier Leroy wrote: > > If the given list has L elements, each with S items, then flatten sho= uld > > O((L*S)*L) =3D O(S*L^2) time, since you have to keep on churning thro= ugh > > every single element in the ever-expanding l at every recursive flatt= en > > call. That's too bad. > > Here's an experiment I tried: > > [...] > > I guess it looks linear because of the small input size. > > It's always a good idea to do experimental measurements to confirm a > complexity analysis, just to make sure you haven't goofed. But when > the measurements disagree with the analysis, you're supposed to go > back to the analysis and find the flaw in it, not discard the > experiment :-) > > More seriously: l1 @ l2 takes time O(length(l1)); the length of l2 > doesn't matter since l2 isn't copied. This gives List.flatten a > complexity of O(S*L) in your example (list of length L, each list > element being of length S). =20 You are right. I had the incorrect mental picture of (@) being called wit= h the=20 increasingly large first argument: S + 2*S +... + (L-1)*S =3D O(S*L^2).=20 Cheers Oleg > This is optimal for immutable, > singly-linked lists. > > - Xavier Leroy ------------------- 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