3
$\begingroup$

Just a simple question that will help me do the programming homework:

I've got two sets and need to check if they're equal. I've already implemented intersection and union methods, now I've got to implement a method which checks if $S_1$ and $S_2$ are equal. So, instead of repeating the code, I'd like to use intersection and union methods.

Now, a math question: is $|S_1 \cup S_2| = |S_1|$ a sufficient condition to say two sets are equal?

3 Answers 3

6

No, the condition you wrote does not suffice: Not even $S_1\cup S_2=S_1$ ensures equality; it simply says that $S_2$ is a subset of $S_1$.

Now, if you know that $S_1\cup S_2=S_1\cap S_2$, do you see how to conclude equality of $S_1$ and $S_2$?

By the way, I assume you are working with finite sets? If so, then $|S_1\cup S_2|=|S_1\cap S_2|$ will suffice. This won't be enough if you want you condition to work for infinite sets as well.

  • 0
    Yes, I'm aware of the $p$roblem with the $p$owers of infini$t$e sets :) However, I'm working with finite sets, so I'll use the condition you've $p$rovided. Thank you.2011-04-30
2

No. For example let $S_2$ be the empty set, or any proper subset of $S_1$. But the idea works fine as long as you add that $S_1$ and $S_2$ have the same number of elements.

  • 0
    @Zhen Lin: Indeed. But in a programming context, that is a reasonable assumption.2011-04-30
0

Take $S_1 = \{1,2 \}$ and $S_2 = \emptyset$. Then $|S_1 \cup S_2| = |S_1|$ but $S_1 \neq S_2$.