From: Jon Harrop <jon@jdh30.plus.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Complexity of Set.union
Date: Fri, 25 Feb 2005 22:36:35 +0000 [thread overview]
Message-ID: <200502252236.35567.jon@jdh30.plus.com> (raw)
In-Reply-To: <7f8e92aa0502251350202ec368@mail.gmail.com>
On Friday 25 February 2005 21:50, Radu Grigore wrote:
> > > Did you mean "of two equal height sets such that all elements of the
> > > first set are smaller than all elements of the second set"?
> >
> > Yes, that's what I meant. :-)
>
> In that case the current Set.union simply adds elements repeatedly
> from the set with small height to the set with big height.
Yes, I agree with everything you said.
> > Having said that, wouldn't it take the Set.union function O(log n + log
> > N) time to prove that the inputs are non-overlapping, because it would
> > have to traverse to the min/max elements of both sets?
>
> I agree. Also, such a check looks ugly to me (for a standard library).
I think I agree here too. Assuming that such special cases cannot be handled
without incurring a performance cost (which I'm not sure about), I'd
definitely go for the simplest code.
Regarding Don's question about what an imperative programmer would have to do
to write efficient code. My interpretation is now that they would have to
work out which of the data structures they could destroy. Then they would
have to convert the purely functional implementation into one which performs
in-place operations.
This is fairly easy in the case of my "nth" program because the main function
"accumulates" its result and, therefore, this accumulator can be overwritten.
I can imagine it quickly becoming a headache though. For example, if there
were any non-trivial branches in the middle of the function.
Whilst writing the C++ implementation I remembered how I first became
interested in functional programming - I noticed that I could only write
correct C++ programs when I littered everything with "const". :-)
I'll post my detailed performance analysis when its done...
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://ffconsultancy.com
prev parent reply other threads:[~2005-02-25 22:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-24 9:20 Set union Jon Harrop
2005-02-25 10:56 ` [Caml-list] " Radu Grigore
2005-02-25 17:30 ` Jon Harrop
2005-02-25 17:48 ` Xavier Leroy
2005-02-25 19:47 ` [Caml-list] Complexity of Set.union Jon Harrop
2005-02-25 21:50 ` Radu Grigore
2005-02-25 21:52 ` Radu Grigore
2005-02-25 22:31 ` Radu Grigore
2005-02-25 22:36 ` Jon Harrop [this message]
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=200502252236.35567.jon@jdh30.plus.com \
--to=jon@jdh30.plus.com \
--cc=caml-list@yquem.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