caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <visigoth@cs.cmu.edu>
To: Eric Merritt <cyberlync@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Simple question
Date: 12 Apr 2002 15:55:59 -0400	[thread overview]
Message-ID: <86it6wlmi8.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <20020412191529.79299.qmail@web13007.mail.yahoo.com>

>>>>> "em" == Eric Merritt <cyberlync@yahoo.com> writes:

    em> by this I assume that the '@' function is not as strait
    em> forward as I thought it would be? In what manner does it
    em> append to the list to make the time 0(n^2)? -just curious.

Actually, it's O(n) because it's straightforward and doesn't cause
side-effects.  The O(n^2) is when it is used n times.  Here's an
implementation that works similarly:

let rec append a b = match (a,b) with
  | [], _ -> b
  | h::t, _ -> h :: append t b

If you keep appending one element onto the end of a list, you can see
that append has to run down the entire first list each time to build a
new list with your new value at the end.  If you append one item at
the beginning each time, it behaves substatntially like :: does.

So (@) is O(n) with n being the size of the first argument.

John.
-------------------
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


  reply	other threads:[~2002-04-15 13:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-12 15:51 [Caml-list] Applications written in O'Caml Vincent Foley
2002-04-12 16:15 ` Benjamin C. Pierce
2002-04-12 16:44   ` [Caml-list] Simple question Eric Merritt
2002-04-12 16:59     ` Remi VANICAT
2002-04-12 17:04     ` Maxence Guesdon
2002-04-12 17:57       ` Remi VANICAT
2002-04-12 19:15         ` Eric Merritt
2002-04-12 19:55           ` John Prevost [this message]
2002-04-15 20:08             ` Eric Merritt
2002-04-12 20:20           ` james woodyatt
2002-04-13 11:10           ` Remi VANICAT
2002-04-13 12:45   ` [Caml-list] Applications written in O'Caml Oliver Bandel
2002-04-13 19:07     ` Benjamin C. Pierce
2002-04-12 16:40 ` Maxence Guesdon
2002-04-12 17:04 ` Warp
2002-04-13  2:27 ` eijiro_sumii
2002-04-13  3:28   ` Michael Vanier
2002-04-15  8:16 ` Nicolas barnier
2002-04-16 10:12 ` Jacek Chrzaszcz

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=86it6wlmi8.fsf@laurelin.dementia.org \
    --to=visigoth@cs.cmu.edu \
    --cc=caml-list@inria.fr \
    --cc=cyberlync@yahoo.com \
    /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;
as well as URLs for NNTP newsgroup(s).