caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Baptiste Rouquier <jean-baptiste.rouquier@ens-lyon.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] how to calculate a "xor"
Date: Wed, 10 Dec 2003 21:37:07 +0100	[thread overview]
Message-ID: <3FD783F3.8020504@ens-lyon.org> (raw)
In-Reply-To: <20031205200829.7e29a2c6.Damien.Pous@ens-lyon.fr>

Damien wrote:

> Hi algorithmers,
>
> Given two sets A and B, I want to calculate A\B _and_ B\A.
> The sets are represented by lists.

Consider the case A = [a_1; a_3; a_5; ...] and B = [a_2; a_4; a_6; ...] 
where a_i < a__{i+1}.
I think it's a worst case for any algorithm.

> without using an order to sort the lists,

that is, if the only allowed comparison is "="

> is there something better than (...) (O(n2)) ?

In my example, any algorithm has to test if a_{2i} = a_{2j+1}. So the 
worst case is O(n2).


> with an order, is there something better than (O(n*ln n)) ?

Consider the case where an algorithm M hasn't sorted B. So there are 2 
consecutive elements, say a_4 and a_6, that hasn't been compared 
(directly or with transitivity). a_5 can't have been compared to both 
a_4 and a_6, let's consider a_5 hasn't been compared to a_4. Then M 
can't decide whether a_4 = a_5 or not, even using transitivity.

This proove that any algorithm has to sort both A and B in my example, 
so the worst case is
O(n ln n).

See you soon,
Jean-Baptiste.

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


      parent reply	other threads:[~2003-12-10 21:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-05 19:08 Damien
2003-12-06  5:08 ` [Caml-list] " Alan Post
2003-12-10 20:37 ` Jean-Baptiste Rouquier [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=3FD783F3.8020504@ens-lyon.org \
    --to=jean-baptiste.rouquier@ens-lyon.org \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).