<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/458ac04874c1d4210349ca4aef0cefb1"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-12-07T10:28:25"
  subject="Re: [Caml-list] function"
  prev="2002/12/5581c0bd84fc85a1433cc7954b60ed48"
  next="2002/12/2deaecb005361aa08c2faca67fcaa675"
  prev-in-thread="2002/12/5581c0bd84fc85a1433cc7954b60ed48"
  next-in-thread="2002/12/938da7b77f8b3b294f4ae5d5dade6d4f"
  prev-thread="2002/12/e69ce402ec37766285461eb0c4583d17"
  next-thread="2002/12/838549db9eab58c179d31f32eefdf381"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] function">
<msg 
  url="2002/12/67f44329195eaf652b43093fd3ca01ba"
  from="altavillasalvatore@libero.it &lt;altavillasalvatore@l...&gt;"
  author="altavillasalvatore@libero.it"
  date="2002-12-02T15:55:08"
  subject="[Caml-list] function">
<msg 
  url="2002/12/aa10f5e9e0a36a35e6d25918c9404768"
  from="sebastien FURIC &lt;sebastien.furic@t...&gt;"
  author="sebastien FURIC"
  date="2002-12-02T16:30:12"
  subject="Re: [Caml-list] function">
</msg>
<msg 
  url="2002/12/01b22e6f3b5a5470860e77cba7c48d8e"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-02T17:35:49"
  subject="Re: [Caml-list] function">
</msg>
<msg 
  url="2002/12/9b00251c6816fbc02c4a06d09719d33e"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-03T23:21:13"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/3a29f1975beda5e8c692774800ed0d87"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-12-05T10:01:05"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/019830184ea14462c3df69900b5a0cda"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-05T20:24:25"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/6a861191e568645e8947da7ef9a991bc"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-05T23:01:21"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/5581c0bd84fc85a1433cc7954b60ed48"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-06T21:30:52"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/458ac04874c1d4210349ca4aef0cefb1"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-12-07T10:28:25"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/938da7b77f8b3b294f4ae5d5dade6d4f"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-07T17:32:03"
  subject="Re: [Caml-list] function">
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2002/12/ae8917859b7799193678c7a51ce64247"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-05T20:47:21"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/87e12bef39b1bf9fc066aa51f3deb525"
  from="Pal-Kristian Engstad &lt;engstad@n...&gt;"
  author="Pal-Kristian Engstad"
  date="2002-12-05T21:04:47"
  subject="Re: [Caml-list] function">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
&gt; If the given list has L elements, each with S items, then flatten should 
&gt; O((L*S)*L) = O(S*L^2) time, since you have to keep on churning through
&gt; every single element in the ever-expanding l at every recursive flatten 
&gt; call.  That's too bad.
&gt; Here's an experiment I tried:
&gt; [...]
&gt; 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).  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

</contents>

</message>

