Mathematics for Computer Science 201-N11 • CEGEP, Montreal
Corrected exercises: set theory and relations (201-N11)
This is the corrected exercise set on sets and relations for Mathematics for Computer Science, 201-N11, the mathematics course taken by CEGEP students in computer science programs. Part A covers the basics: membership and inclusion, the power set and cardinality, union, intersection, difference, complement and the Cartesian product, De Morgan's laws proved by double inclusion and then by membership table, Venn diagrams with the inclusion-exclusion principle, and binary relations seen as sets of ordered pairs, with their Boolean matrix and their directed graph. Part B rises to exam level: the four properties tested on three relations, equivalence relations and partitions with the example of hash tables, a survey with three sets where three quantities with similar names are dangerously alike, and a partial order problem with composition and the transitive closure.
The thread of the set: a set is defined by its elements, a relation by its ordered pairs. Every property is therefore checked on the list, never on the name of the relation or on intuition. To disprove, one counterexample is enough; to prove, you must sweep through every case, and the diagram is there to organize that sweep.
The pitfalls named explicitly in the solutions: confusing ∈ and ⊆, believing that “in A∩B” means “in exactly two sets”, thinking that not symmetric implies antisymmetric, and forgetting the outer region of the Venn diagram.
Self-checking setType your answers and check them question by question: the page tells you right or wrong before you open the solution. With an account, every answer right on the first try earns points, and your right answers stay filled in when you come back.
•x∈A links an element to a set; A⊆B links two sets. 3 and {3} are not the same thing.
•∣P(X)∣=2∣X∣: each element is either taken or left out.
•∅⊆A always, ∅∈P(A) always, but ∅∈A almost never.
•De Morgan: A∪B=A∩B and A∩B=A∪B. And A∖B=A∩B.
•Inclusion-exclusion: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣, and for three sets you subtract the three pairwise intersections, then add back the triple intersection.
•Filling in a Venn diagram ALWAYS starts with the central region.
•A relation on E is a subset of E×E: it is described by its ordered pairs, its Boolean matrix or its directed graph.
•Reflexive, antisymmetric, transitive: an ORDER relation. Reflexive, symmetric, transitive: an EQUIVALENCE relation.
•The classes of an equivalence relation form a partition: nonempty, pairwise disjoint, with union E.
•Transitive closure: the union of all the powers S,S2,S3,…; a pair (i,j) belongs to it if there is a path from i to j.
Part A: the basics (/50)
Exercise 1: Notation: membership, inclusion, power set
Let E={1,2,3,4,5,6,7,8,9,10}, A={x∈E:x is even} and B={x∈E:x≤5}. A set is entirely determined by its elements: neither order nor repetition counts.
a) Write A and B in roster form.
b) Fill in with ∈, ∈/, ⊆ or ⊈: 3…A; {3}…B; 3…B; {2,4}…A.
c) Write all the elements of P({a,b,c}).
d) How many elements does P(X) have if X has n? And for X=E?
e) Does the empty set ∅ belong to A? Is it a subset of A? Does it belong to P(A)?
Show the solution
Answers
a)A={2,4,6,8,10} and B={1,2,3,4,5}
b)3∈/A, {3}⊆B, 3∈B, {2,4}⊆A
c){∅,{a},{b},{c},{a,b},{a,c},{b,c},{a,b,c}}, that is, 8 subsets
d)2n subsets, so 210=1024 for E
e)∅∈/A, but ∅⊆A and ∅∈P(A)
a)
A={2,4,6,8,10} and B={1,2,3,4,5}. Set-builder notation gives the rule, roster form gives the list: switching from one to the other is the first reflex of the chapter, because a property is much faster to check on a list.
b)
3∈/A, since 3 is odd. {3}⊆B, since the only element of {3} is in B. 3∈B. {2,4}⊆A. The point not to miss: 3 and {3} are not the same thing. The first is a number, the second is a set containing that number. You write 3∈B but {3}⊆B, and never the other way around.
c)
P({a,b,c})={∅,{a},{b},{c},{a,b},{a,c},{b,c},{a,b,c}}, that is, 8 subsets. List them by increasing size: it is the only way not to forget any, and the count by size must give 1,3,3,1.
d)
Each element of X is either taken or left out, independently of the others: that makes 2 choices repeated n times, so ∣P(X)∣=2n. For E, which has 10 elements, 210=1024 subsets. The link with the chapter on number systems is direct: a subset of X is exactly a binary word of n bits, where the bit in position k says whether element k is taken.
e)
∅∈/A: the elements of A are numbers, not sets. But ∅⊆A: inclusion requires every element of ∅ to be in A, which is vacuously true since there is no element to check. And ∅∈P(A), since P(A) is the set of subsets of A and ∅ is one of them. The three answers differ, and that is what makes the example useful.
Tick the exercises you have done or want to review: a free account, no password, keeps your ticks and your right answers from one visit to the next, tells you which chapter to tackle next and lets you ask for the exercise you are missing. Create your space, an email is enough.
Exercise 2: Set operations and the Cartesian product
Let E={1,2,…,10} be the universal set, A={1,2,3,4,5,6} and B={4,5,6,7,8}. We write A for the complement of A in E.
a) Give A∪B, A∩B, A∖B and B∖A in roster form.
b) Give A and B.
c) How many elements does A×B have? Give three of them.
c)6×5=30 pairs, for example (1,4), (3,8) and (6,5)
d){1,2,3}∪{4,5,6}=A: a partition of A into two disjoint parts
e)6+5−3=8=∣A∪B∣
f)No: (1,4)∈A×B but (4,1)∈/A×B. Same cardinality, 30, different pairs
a)
A∪B={1,2,3,4,5,6,7,8}: all the elements that are in one OR the other, counted only once. A∩B={4,5,6}: those that are in both. A∖B={1,2,3}: in A but not in B. B∖A={7,8}. Note that A∖B and B∖A have nothing to do with each other: the difference is not symmetric.
b)
A={7,8,9,10} and B={1,2,3,9,10}. The complement only makes sense relative to a universal set: without E, the notation A means nothing. Check: ∣A∣+∣A∣=6+4=10=∣E∣.
c)
A×B is the set of ORDERED pairs (a,b) with a∈A and b∈B: it has 6×5=30 of them. For example (1,4), (3,8) and (6,5). The Cartesian product produces pairs, not elements: (1,4) is neither a number nor a two-element set.
d)
A∖B={1,2,3} and A∩B={4,5,6}; their union is {1,2,3,4,5,6}=A. The identity is general: every element of A is either in B or not, and these two cases give exactly the two pieces. It is a partition of A into two disjoint parts, which explains why the cardinalities add up here with no correction.
e)
∣A∣=6, ∣B∣=5, ∣A∩B∣=3, so the formula gives 6+5−3=8. And ∣A∪B∣=∣{1,…,8}∣=8. The formula works. The reason is that adding ∣A∣ and ∣B∣ counts the common elements twice: one copy must therefore be subtracted.
f)
No. A×B contains (1,4), but not (4,1), since 1∈/B. Yet (4,1)∈B×A. The two products have the same cardinality, 30, but they are not the same pairs. An ordered pair is ordered, and that is the whole difference with an unordered pair: (a,b)=(c,d) requires a=c AND b=d.
Exercise 3: De Morgan and proofs by double inclusion
Two sets are equal when each is a subset of the other: this is proof by double inclusion, and it is always written up the same way. Take an arbitrary x in the first set, show that it is in the second, then do it again in the other direction. A membership table, where you write 1 when x is in the set and 0 otherwise, gives the same verdict in four rows.
a) Prove by double inclusion that A∪B=A∩B.
b) Establish A∩B=A∪B with a membership table.
c) Show that A∖B=A∩B.
d) The symmetric difference is AΔB=(A∖B)∪(B∖A). Express ∣AΔB∣ in terms of the cardinalities of A, B and A∩B.
e) Is the equality A∖(B∖C)=(A∖B)∖C true?
Show the solution
Answers
a)A∪B=A∩B: it is De Morgan carried over to sets
b)Both columns read 0,1,1,1: the equality is established
c)A∖B=A∩B
d)∣AΔB∣=∣A∣+∣B∣−2∣A∩B∣, that is, 6+5−6=5 on the example
e)FALSE: with A={1}, B={2}, C={1}, you get {1} on one side and ∅ on the other
a)
First inclusion. Let x∈A∪B. Then x∈/A∪B, so x is neither in A nor in B; hence x∈A and x∈B, that is, x∈A∩B. Reverse inclusion. Let x∈A∩B. Then x∈/A and x∈/B, so x is in neither of the two, so x∈/A∪B, that is, x∈A∪B. The two inclusions give the equality. This is exactly De Morgan's law from logic, carried over to sets: the negation of an OR is an AND of negations.
b)
Four rows, depending on whether x belongs to A and to B or not. Columns (x∈A,x∈B), then A∩B, then A∩B, then A, B and their union. Row (1,1): A∩B is 1, its complement 0; A∪B is 0∪0=0. Row (1,0): 0, so 1; and 0∪1=1. Row (0,1): 0, so 1; and 1∪0=1. Row (0,0): 0, so 1; and 1∪1=1. The two final columns are identical on all four rows: the equality is established. The table is faster than double inclusion, but it only generalizes cleanly to identities involving a small number of sets.
c)
x∈A∖B means x∈A and x∈/B, which can be written x∈A and x∈B, that is, x∈A∩B. The two expressions translate the same sentence, so the equivalence is immediate in both directions. This identity is the one that lets you eliminate the difference symbol everywhere and work only with union, intersection and complement.
d)
A∖B and B∖A are disjoint, so the cardinalities add up: ∣AΔB∣=∣A∖B∣+∣B∖A∣. Now ∣A∖B∣=∣A∣−∣A∩B∣, and likewise for the other. Hence ∣AΔB∣=∣A∣+∣B∣−2∣A∩B∣. The factor 2 is the point to understand: the intersection is removed twice, once on each side, because it is precisely what the symmetric difference excludes. On the example of the previous exercise: 6+5−2(3)=5, and indeed AΔB={1,2,3,7,8}.
e)
No. Counterexample: A={1}, B={2}, C={1}. On the left, B∖C={2} and A∖{2}={1}. On the right, A∖B={1}, then {1}∖C=∅. We get {1} on one side and ∅ on the other: the difference is not associative. A single counterexample is enough to disprove an identity claimed for all sets, and it is best looked for with one-element sets, where everything can be checked in your head.
Exercise 4: Venn diagrams and the inclusion-exclusion principle
Three subsets A, B and C of a set E with 60 elements satisfy: ∣A∣=27, ∣B∣=20, ∣C∣=29, ∣A∩B∣=8, ∣A∩C∣=10, ∣B∩C∣=7 and ∣A∩B∩C∣=3. The diagram below marks out the eight regions to fill in.
a) Fill in the eight regions of the diagram, starting from the center.
b) Compute ∣A∪B∪C∣ with the inclusion-exclusion formula, then check on the diagram.
c) How many elements are in none of the three sets?
d) How many elements are in exactly two of the three sets?
e) Why does the formula add the term ∣A∩B∩C∣ at the end?
e)The elements in the center are counted three times, then removed three times: their balance is zero, so they must be added back once
a)
ALWAYS start from the center, otherwise you subtract quantities that have already been removed. Center: ∣A∩B∩C∣=3. Region A∩B only: 8−3=5. Region A∩C only: 10−3=7. Region B∩C only: 7−3=4. Region A only: 27−5−7−3=12. Region B only: 20−5−4−3=8. Region C only: 29−7−4−3=15. Outside: 60−(12+8+15+5+7+4+3)=60−54=6. Check: the eight regions add up to 60, the cardinality of E.
b)
∣A∪B∪C∣=27+20+29−8−10−7+3=54. On the diagram, the union is the sum of the seven inner regions: 12+8+15+5+7+4+3=54. The two methods agree, and it is this double calculation that secures the result.
c)
60−54=6 elements are outside the union. This is the outer region of the diagram, the one that is systematically forgotten when the rectangle of the universal set is not drawn.
d)
Exactly two: these are the three lens-shaped regions, 5+7+4=16 elements. Watch the wording: ∣A∩B∣=8 also counts the 3 elements in the center, which are in THREE sets. “In exactly two” is not “in A∩B”, and this nuance is the classic trap of survey problems.
e)
Because the elements in the center are counted three times by ∣A∣+∣B∣+∣C∣, then removed three times by the three pairwise intersections: their balance is zero, whereas they must count once. So they are added back once. The same compensation argument, applied to an element lying in exactly two sets, gives 2−1=1: it is counted once, as it should be, and nothing needs correcting for it.
Exercise 5: Binary relations: ordered pairs, matrix and directed graph
A binary relation R on a set E is simply a subset of E×E: it is the list of the ordered pairs (x,y) for which we write xRy. Nothing else. Every property of a relation is therefore checked on its ordered pairs, never on the intuition carried by the word used to name it.
Take E={1,2,3,4} and the relation xRy defined by “x divides y”. The arrow diagram below shows all of its arrows.
a) Write R in roster form, as a set of ordered pairs.
b) How many different relations can be defined on E?
c) Write the Boolean matrix M of R, with Mij=1 when iRj.
d) Give the image of 2 and the set of preimages of 4.
e) Is the relation “x divides y” on E a function? Justify.
c)Upper triangular matrix, full first row, 8 entries equal to 1
d)Image of 2: {2,4}, second ROW. Preimages of 4: {1,2,4}, fourth COLUMN
e)No: 1 has four images. A function has at most one 1 per row
a)
R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),(3,3),(4,4)}, that is, 8 ordered pairs. You find them by sweeping through the 16 possible pairs and keeping those where the division comes out exactly: 1 divides everything, 2 divides 2 and 4, 3 divides 3, and 4 divides 4.
b)
A relation on E is a subset of E×E, which has 4×4=16 ordered pairs. There are therefore 216=65,536 possible relations, one per subset of pairs. The link with exercise 1 is direct: each pair is chosen or not, which is a 16-bit word.
c)
Ordering the indices from 1 to 4: M=1000110010101101. The first row is full, because 1 divides everything; the matrix is upper triangular, because a divisor of a nonzero number is less than or equal to it. Check: the matrix has 8 entries equal to 1, as many as R has ordered pairs.
d)
The image of 2 is {y:2Ry}={2,4}, that is, the 1s of the second ROW. The preimages of 4 are {x:xR4}={1,2,4}, that is, the 1s of the fourth COLUMN. Reading a row or a column does not give the same thing, and this is the first source of error with relation matrices.
e)
No. A function assigns to each starting element AT MOST one image, but 1 is related to 1, 2, 3 and 4: four images. A relation is a function exactly when each row of its matrix contains at most one 1; here the first row contains four. This is the essential difference between the two notions: a function is a very special case of a relation.
Part B: problems and reasoning (/50)
Exercise 6: The four properties of a relation
Four properties are tested on the ordered pairs. Reflexive: (x,x)∈R for every x. Symmetric: if (x,y)∈R then (y,x)∈R. Antisymmetric: if (x,y)∈R and (y,x)∈R then x=y. Transitive: if (x,y)∈R and (y,z)∈R then (x,z)∈R. To disprove, one counterexample is enough; to prove, you must sweep through every case.
We study three relations: R1 is “x divides y” on {1,2,3,4}; R2={(1,2),(2,1),(3,3)} on {1,2,3}; R3 is “x+y is even” on {1,2,3,4}.
a) Study the four properties of R1 and state what kind of relation it is.
b) Study the four properties of R2.
c) Study the four properties of R3 and state what kind of relation it is.
d) Can a relation be both symmetric and antisymmetric? Give an example.
e) How do you recognize each property on the Boolean matrix?
Show the solution
Answers
a)Reflexive, antisymmetric, transitive, not symmetric: it is a partial ORDER, 2 and 3 being incomparable
b)Symmetric only: neither reflexive, nor antisymmetric, nor transitive
c)Reflexive, symmetric, transitive, not antisymmetric: it is an EQUIVALENCE, the one of parity
d)Yes, but it then contains only pairs on the diagonal: equality is the example
e)Full diagonal, matrix equal to its transpose, never Mij and Mji off the diagonal, and M2≤M
a)
Reflexive: every integer divides itself, the four pairs (x,x) are there. Symmetric: no, (1,2)∈R1 but (2,1)∈/R1, one counterexample is enough. Antisymmetric: if x divides y and y divides x with x,y positive, then x=y; you can also check it pair by pair, no symmetric pair appears off the diagonal. Transitive: if x divides y and y divides z, then x divides z. Reflexive, antisymmetric and transitive: R1 is an ORDER relation, and this order is partial since 2 and 3 are not comparable.
b)
Reflexive: no, (1,1)∈/R2. Symmetric: yes, (1,2) and (2,1) are both present, and (3,3) is its own mirror image. Antisymmetric: no, (1,2) and (2,1) are there although 1=2. Transitive: no, (1,2) and (2,1) should force (1,1), which is missing. So R2 is neither an order nor an equivalence: it is just an arbitrary relation, and that is the most frequent case.
c)
Reflexive: x+x=2x is even, so yes. Symmetric: x+y=y+x, so yes. Antisymmetric: no, (1,3) and (3,1) are there with 1=3. Transitive: if x+y and y+z are even, then x and y have the same parity, and so do y and z, hence x and z as well, so x+z is even. Reflexive, symmetric and transitive: R3 is an EQUIVALENCE relation, the one that sorts integers by parity.
d)
Yes, but it is very restrictive: if (x,y)∈R with x=y, symmetry forces (y,x)∈R and antisymmetry then forces x=y, a contradiction. A relation that is both symmetric and antisymmetric therefore contains only pairs on the diagonal. Example: equality, R={(x,x):x∈E}. Symmetric and antisymmetric are not opposites: they are two independent conditions that can be true together, false together, or one without the other.
e)
Reflexive: the diagonal contains only 1s. Symmetric: the matrix equals its transpose. Antisymmetric: off the diagonal, never Mij and Mji both equal to 1. Transitive: the Boolean square M2 has no 1 where M has a 0, which is written M2≤M. This last reading builds the bridge to the chapter on matrices: a 1 in position (i,j) of M2 signals a path of length 2, and transitivity requires such a path always to have its direct shortcut.
Exercise 7: Equivalence relations, classes and partitions
On E={0,1,2,…,14}, define x∼y when x and y leave the same remainder when divided by 5, which is written x≡y(mod5). An equivalence relation cuts the set into packets with nothing left over and no overlap: it is the mechanism behind hash tables.
a) Check that ∼ is an equivalence relation.
b) Give the equivalence classes in roster form.
c) Check that these classes form a partition of E.
d) How many classes are there? How many elements in each?
e) In a hash table with 5 buckets using the function h(x)=xmod5, what do the classes represent?
f) Can two equivalence classes have an element in common without being equal?
Show the solution
Answers
a)Reflexive, symmetric and transitive: the relation is defined by the equality of a quantity
c)No empty class, pairwise disjoint, with union E: it is a partition
d)5 classes of 3 elements, and 5×3=15
e)The content of one bucket: the elements equivalent modulo 5 collide
f)No: two classes are either equal or disjoint, by transitivity
a)
Reflexive: x obviously leaves the same remainder as itself. Symmetric: if x and y leave the same remainder, then so do y and x, the condition is symmetric as written. Transitive: if x and y leave the same remainder r, and y and z the same remainder, that remainder is still r, so x and z leave the same remainder. The three properties hold: ∼ is an equivalence. None of these checks requires any calculation, because the relation is defined by the equality of a quantity, and equality is always an equivalence.
b)
Class of 0: {0,5,10}. Class of 1: {1,6,11}. Class of 2: {2,7,12}. Class of 3: {3,8,13}. Class of 4: {4,9,14}. We write [r] for the class of the remainder r; for example [2]={2,7,12}, and [7] denotes the SAME set. A class has as many names as it has elements, which is puzzling at first but causes no trouble once accepted.
c)
Three conditions. No class is empty: each has three elements. They are pairwise disjoint: two different remainders cannot coexist for the same number, since the remainder of Euclidean division is unique. Their union is E: every integer in E has a remainder, so it belongs to a class. It is indeed a partition.
d)
Five classes, as many as the possible remainders 0,1,2,3,4, with 3 elements each. Check: 5×3=15=∣E∣. This regularity comes from the fact that E contains exactly three blocks of 5 consecutive integers; on {0,…,13} the classes would no longer all have the same size.
e)
Each class is the content of one bucket: the elements that collide are exactly those that are equivalent modulo 5. The number of buckets is the number of classes, and evenly sized classes are precisely what is asked of a good hash function. If the data all left the same remainder, everything would land in the same bucket and searching would become linear again.
f)
No. If z belongs to the class of x and to that of y, then x∼z and z∼y, so x∼y by transitivity, and the two classes contain exactly the same elements. Two classes are therefore either equal or disjoint, never partly overlapping. This dichotomy is what guarantees a partition, and it rests entirely on transitivity.
Exercise 8: Five statements to correct
Each of the following five statements is FALSE. Say why and give the correct statement.
1) “The empty set belongs to every set.”
2) “If X has n elements, then P(X) has 2n.”
3) “A relation that is not symmetric is antisymmetric.”
4) “∣A∪B∣=∣A∣+∣B∣.”
5) “A×B=B×A, since they are the same elements taken two at a time.”
Show the solution
Answers
1)FALSE: ∅⊆A always, ∅∈P(A) always, but ∅∈A almost never
2)FALSE: ∣P(X)∣=2n, and for n=3 that makes 8, not 6
3)FALSE: the two properties are independent. R={(1,2),(2,1),(1,3)} has neither
4)FALSE: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣, the plain equality requiring disjoint sets
5)FALSE: A×B={(1,2)} and B×A={(2,1)} have no element in common
1)
FALSE. It is inclusion that is universal, not membership: ∅⊆A for every A, but ∅∈A only if A contains the empty set as an element. Counterexample: A={1,2} contains only the numbers 1 and 2. Correct statement: ∅⊆A always, and ∅∈P(A) always, but ∅∈A almost never.
2)
FALSE. The number of subsets doubles with each element added, it does not increase by a fixed amount: it is 2n, not 2n. Counterexample: for n=3, we counted 8 subsets, whereas 2n=6. Correct statement: ∣P(X)∣=2∣X∣, because each element is taken or left out independently of the others.
3)
FALSE. The two properties are independent, and a relation may satisfy neither. Counterexample: R={(1,2),(2,1),(1,3)} on {1,2,3} is not symmetric, since (3,1) is missing, and not antisymmetric, since (1,2) and (2,1) coexist with 1=2. Correct statement: symmetric and antisymmetric are two distinct conditions; the negation of one cannot be deduced from the other.
4)
FALSE. The common elements would be counted twice. Counterexample: A={1,2} and B={2,3} give ∣A∪B∣=3 whereas ∣A∣+∣B∣=4. Correct statement: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣, and the plain equality holds only if A and B are disjoint.
5)
FALSE. A Cartesian product is made of ORDERED pairs. Counterexample: with A={1} and B={2}, we have A×B={(1,2)} and B×A={(2,1)}, two sets with no element in common. Correct statement: A×B and B×A always have the same cardinality, ∣A∣×∣B∣, but they are equal only if A=B or if one of the two is empty.
Exercise 9: Problem: a survey on programming languages
A survey covers 120 students in a computer science program. It shows that 78 know Python, 64 know Java and 45 know the C++ language. In addition, 40 know Python and Java, 28 know Python and C++, 22 know Java and C++, and 15 know all three.
The figure below represents the situation.
a) How many students know at least one of the three languages?
b) How many know none of them?
c) How many know Python only?
d) How many know exactly two of the three languages?
e) The internship office claims that 30 students know Java without knowing Python. Is it right?
f) A coordinator announces that 50 students know Python and Java only. Show that this figure is impossible.
Show the solution
Answers
a)78+64+45−40−28−22+15=112
b)120−112=8
c)78−40−28+15=25
d)25+13+7=45
e)No: Java without Python is 64−40=24, and Java only is 17. The office is off by 6
f)The region is 40−15=25, and in any case it cannot exceed ∣P∩J∣=40
a)
Inclusion-exclusion: 78+64+45−40−28−22+15=187−90+15=112. Order-of-magnitude check: the result must lie between the largest of the three counts, 78, and their sum, 187; 112 is indeed in that interval.
b)
120−112=8 students know none of the three languages. This is the outer region of the diagram, and it appears in none of the data of the problem: it has to be computed.
c)
Python only: from 78, remove those who also know Java or C++, without forgetting to put the center back. 78−40−28+15=25. The +15 correction is essential: the 15 students who know all three were removed twice, once with the 40 and once with the 28.
d)
Python and Java only: 40−15=25. Python and C++ only: 28−15=13. Java and C++ only: 22−15=7. Total: 25+13+7=45 students know exactly two languages. The complete diagram then reads: 25,17,10 for the single regions, 25,13,7 for the doubles, 15 in the center, 8 outside, and the sum is indeed 120.
e)
Java without Python is ∣J∣−∣P∩J∣=64−40=24, not 30. The office is off by 6. The figure 30 matches none of the natural quantities, and the most likely confusion is with “Java only”, which equals 17. Three different quantities carry similar names: Java (64), Java without Python (24) and Java only (17); telling them apart is what the whole problem is about.
f)
“Python and Java only” equals 40−15=25. The figure 50 is impossible for an even stronger reason: this region is contained in P∩J, which has only 40 students, so it can in no case exceed 40. The count of a region can never exceed that of a set containing it, and this inequality is the fastest check for rejecting an absurd figure before any calculation.
Exercise 10: Problem: partial order, composition and transitive closure
Let E={a,b,c}. Equip P(E) with inclusion ⊆. Then consider, on {1,2,3,4}, the relation S={(1,2),(2,3),(3,4)}, called the successor relation, and its composite S∘S, defined by: x(S∘S)z if there exists y such that xSy and ySz.
a) Show that ⊆ is an order relation on P(E).
b) Are the subsets {a} and {b} comparable? What does the word “partial” mean?
c) Give a chain of maximum length in P(E).
d) Compute S∘S, then S∘S∘S.
e) Find the transitive closure of S, that is, the smallest transitive relation containing S.
f) Is S transitive? Is its transitive closure an order relation?
Show the solution
Answers
a)Reflexive, antisymmetric and transitive: inclusion is an order on P(E), which has 8 elements
b)Not comparable. “Partial”: there is at least one pair of incomparable elements
c)∅⊊{a}⊊{a,b}⊊{a,b,c}, ∣E∣+1=4 subsets
d)S∘S={(1,3),(2,4)} and S∘S∘S={(1,4)}
e){(1,2),(2,3),(3,4),(1,3),(2,4),(1,4)}, 6 pairs: it is the relation x<y
f)Not transitive. Its closure is a STRICT order, not reflexive; the diagonal must be added to get ≤
a)
Reflexive: X⊆X for every subset X, since every element of X is in X. Antisymmetric: if X⊆Y and Y⊆X, then X and Y have exactly the same elements, so X=Y; this is the very definition of equality by double inclusion. Transitive: if X⊆Y and Y⊆Z, every element of X is in Y, hence in Z. The three properties hold: inclusion is an order relation on P(E), which here has 23=8 elements.
b)
No: {a}⊈{b} and {b}⊈{a}. Two elements are comparable when one of them is related to the other; here neither direction holds. An order is called PARTIAL when there is at least one pair of incomparable elements, and TOTAL when every pair is comparable. The usual order on the real numbers is total; inclusion almost never is. The practical consequence: P(E) cannot be lined up on a single line, it takes a diagram with several levels.
c)
∅⊊{a}⊊{a,b}⊊{a,b,c}: a chain of 4 subsets, each a proper subset of the next. You cannot do longer, since each proper inclusion adds at least one element and there are only three to add starting from ∅. The maximum number of subsets in a chain is therefore ∣E∣+1=4.
d)
S∘S contains the pairs linked by two consecutive arrows: 1→2→3 gives (1,3), and 2→3→4 gives (2,4). So S∘S={(1,3),(2,4)}. Composing once more, only 1→2→3→4 remains: S∘S∘S={(1,4)}. Each further composition lengthens the path by one step and thins out the pairs, until S4=∅, for lack of a path of length 4 in a chain of four vertices.
e)
The transitive closure gathers all the paths of length at least 1: S∪S2∪S3={(1,2),(2,3),(3,4),(1,3),(2,4),(1,4)}, that is, 6 pairs. This is exactly the relation x<y on {1,2,3,4}, as the count confirms: the number of pairs (x,y) with x<y among 4 elements is 24×3=6. You stop at S3 because S4 is empty, and more generally because a path without repetition in a set with n elements has at most n−1 edges.
f)
S is not transitive: (1,2) and (2,3) are in it, but (1,3) is not. Its transitive closure, the relation <, is transitive by construction and antisymmetric, since x<y and y<x are incompatible. But it is NOT reflexive, because (1,1) is not in it: so it is not an order relation in the broad sense, but a STRICT order. To get an order in the broad sense, the diagonal must still be added, which gives ≤ and is called the reflexive transitive closure. This is the operation that Warshall's algorithm performs on the Boolean matrix of a relation, and it links this chapter directly to the one on graphs: a 1 in position (i,j) of the closure means that there is a path from i to j.
Hasse diagram of P({a,b,c}): in blue, the maximal chain ∅⊊{a}⊊{a,b}⊊{a,b,c}; {a} and {b} are joined by no upward path, they are incomparable.
S in navy blue, S2 in orange, S3 in green: their union, six pairs, is the relation x<y.
Something missing from this set?A type of exercise your teacher gives, a problem you are stuck on, a mistake you spotted: tell me, I read every request.
Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space.
Rather not create an account? Write to me directly.
Looking for a 201-N11 Mathematics for Computer Science tutor in Montreal?
Get in touch for a first session. With a B.Sc. in computer science from McGill and an M.Sc. in applied computer science from Concordia, I connect sets and relations to what they become next: SQL queries, hash tables and graphs.