From: Oleg <oleg_inconnu@myrealbox.com>
To: Xavier Leroy <xavier.leroy@inria.fr>,
Issac Trotts <ijtrotts@ucdavis.edu>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] function
Date: Sat, 7 Dec 2002 12:31:33 -0500 [thread overview]
Message-ID: <200212071231.33590.oleg_inconnu@myrealbox.com> (raw)
In-Reply-To: <20021207112814.A23052@pauillac.inria.fr>
On Saturday 07 December 2002 05:28 am, Xavier Leroy wrote:
> > If the given list has L elements, each with S items, then flatten should
> > O((L*S)*L) = O(S*L^2) time, since you have to keep on churning through
> > every single element in the ever-expanding l at every recursive flatten
> > 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).
You are right. I had the incorrect mental picture of (@) being called with the
increasingly large first argument: S + 2*S +... + (L-1)*S = O(S*L^2).
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
next prev parent reply other threads:[~2002-12-07 17:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-02 15:55 altavillasalvatore
2002-12-02 16:29 ` sebastien FURIC
2002-12-02 17:35 ` Oleg
2002-12-03 23:22 ` Issac Trotts
2002-12-05 10:00 ` Pierre Weis
2002-12-05 20:24 ` Issac Trotts
2002-12-05 23:00 ` Oleg
2002-12-06 21:31 ` Issac Trotts
2002-12-07 10:28 ` Xavier Leroy
2002-12-07 17:31 ` Oleg [this message]
2002-12-05 20:46 ` Oleg
2002-12-05 21:06 ` Pal-Kristian Engstad
2002-12-06 7:38 Jeremy Fincher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200212071231.33590.oleg_inconnu@myrealbox.com \
--to=oleg_inconnu@myrealbox.com \
--cc=caml-list@inria.fr \
--cc=ijtrotts@ucdavis.edu \
--cc=xavier.leroy@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox