Cartesian Product and Relations: Inverse, Complement and Worked Examples
Learn how a Cartesian product defines the universe of a relation, then compute inverse and complement operations through small, fully checked examples.
KnowledgeGate Team
Exam prep & CS education

For A={1,2,3}, B={x,y}, and R={(1,x),(2,y),(3,x)}, inversion yields R⁻¹={(x,1),(y,2),(x,3)}, while complementation within A×B yields Rᶜ={(1,y),(2,x),(3,y)}. The operations differ mechanically: inverse reverses selected pairs into B×A, whereas complement keeps coordinate order and selects the unmarked pairs in A×B.
Cartesian product: build the universe in the right order
An ordered pair satisfies (a,b)=(c,d) exactly when a=c and b=d. Position matters, so changing the coordinate order usually changes the pair.
Let A={1,2,3} and B={x,y}. Then
A×B={(1,x),(1,y),(2,x),(2,y),(3,x),(3,y)}.
The first coordinate comes from A and the second comes from B. Reversing the product gives
B×A={(x,1),(x,2),(x,3),(y,1),(y,2),(y,3)}.
Both products contain six pairs, but they are not equal. For example, (1,x) belongs to A×B, while (x,1) belongs to B×A.
The counting rule is |A×B|=|A||B|=3×2=6. One useful edge case is A×∅=∅, whose cardinality is zero. For relation-property tests, composition, equivalence classes, and posets, use Relations in Discrete Mathematics: Properties, Posets and Worked Examples; the calculation here stays with product order, inverse, and complement.
A relation is a selected subset of the Cartesian product
A relation from A to B is any subset of A×B. Use the running relation
R={(1,x),(2,y),(3,x)}.
Each listed pair appears in A×B, so R⊆A×B. Reading the pairs as connections, 1 is related to x, 2 to y, and 3 to x. Here domain(R)={1,2,3} and range(R)={x,y}. In general, a relation need not use every element of its source or target.
The pair list, a two-column mapping, and a 3×2 Boolean matrix are three representations of the same relation. They carry the same information in different layouts:
The pair list records the selected cells directly.
The mapping draws one arrow for each selected pair.
The matrix places
1at(1,x),(2,y), and(3,x), and0in the other three positions.
A marked matrix cell at row a and column b means precisely that (a,b)∈R. Changing the representation does not change the relation or its cardinality. This is useful when a question defines R with pairs but asks you to interpret a matrix or mapping diagram.
The matrix form makes both operations checkable. In row order 1,2,3 and column order x,y, the matrix of R is [[1,0],[0,1],[1,0]]. Transposition gives the 2×3 matrix [[1,0,1],[0,1,0]] for R⁻¹. Complementing instead flips every 1 and 0 in the original 3×2 matrix, giving [[0,1],[1,0],[0,1]] for Rᶜ. Transposition preserves the number of marked cells; complement changes it from |R| to |A×B|-|R|.

Inverse relation: reverse each pair and switch direction
The inverse is defined by R⁻¹={(b,a):(a,b)∈R}. Apply it one pair at a time:
(1,x)→(x,1)(2,y)→(y,2)(3,x)→(x,3)
Therefore, R⁻¹={(x,1),(y,2),(x,3)}⊆B×A. Its domain and range swap roles:
domain(R⁻¹)={x,y}=range(R) and range(R⁻¹)={1,2,3}=domain(R).
Inversion preserves the number of pairs, so |R⁻¹|=|R|=3. Reversing the three pairs once more returns (1,x), (2,y), and (3,x). Hence (R⁻¹)⁻¹=R. Inverse here means reversing ordered pairs, not taking a reciprocal such as 1/x.

Complement of a relation: subtract from the stated universe
Complement requires a declared universe. For a relation from A to B, take U=A×B. Remove the three pairs of R from its six pairs:
Rᶜ=U-R={(1,y),(2,x),(3,y)}.
Thus |Rᶜ|=6-3=3. The actual sets also verify both complement identities: R∪Rᶜ=A×B and R∩Rᶜ=∅. Writing only Rᶜ without declaring its universe can make an answer ambiguous.
Two boundary cases make the universe rule explicit. The complement of the empty relation in A×B is A×B, while the complement of the full relation A×B is empty. If the source or target changes, rebuild the Cartesian product before subtracting; reusing the old universe can create pairs whose coordinates no longer belong to the declared sets.
Inverse and complement now look clearly different. In the switched universe B×A,
(R⁻¹)ᶜ={(x,2),(y,1),(y,3)}.
Meanwhile, reversing every pair of Rᶜ gives
(Rᶜ)⁻¹={(y,1),(x,2),(y,3)}.
Sets ignore listing order, so these are equal. Therefore (Rᶜ)⁻¹=(R⁻¹)ᶜ, provided the complement universe changes correctly from A×B to B×A.
Fully worked exam-style example
Let P={-1,0,2}, Q={p,q}, and S={(-1,p),(0,q),(2,p),(2,q)}. Find P×Q, S⁻¹, the complement Sᶜ relative to P×Q, and |Sᶜ|.
First build the complete universe:
P×Q={(-1,p),(-1,q),(0,p),(0,q),(2,p),(2,q)}.
It contains 3×2=6 pairs. Next reverse only the four selected pairs:
S⁻¹={(p,-1),(q,0),(p,2),(q,2)}.
Finally remove the four pairs of S from the six-pair universe. The two unselected pairs are
Sᶜ={(-1,q),(0,p)}, so |Sᶜ|=2.
Two sanity checks catch most transcription errors:
|S|+|Sᶜ|=4+2=6=|P×Q|.|S⁻¹|=4=|S|.
Cardinality shortcuts and the number of possible relations
Take fresh sets C={1,2,3,4} and D={a,b,c}. Without listing any pair,
|C×D|=4×3=12.
Every relation from C to D is a subset of this 12-element product. Each pair has two choices, selected or not selected, so the number of possible relations is 2¹²=4096. This count includes the empty relation and the full relation C×D.
The 4096 count is for arbitrary relations, not functions. A function from C to D must choose exactly one D-value for each of four C-elements, so it has 3^4=81 possibilities. The relation count gives every one of 12 pairs an independent yes-or-no choice, whereas the function count gives each source element one of three target choices. Keep those models separate.
For ten solved questions that add relation composition, set ordering, and constrained Cartesian powers to these pair traces, continue with Cartesian Product, Relation, Inverse and Complement MCQs: 10 Solved Questions.
Traps that change the answer
Reversing the product. Replacing
A×BwithB×Achanges(1,x)to(x,1). Write the source and target above the coordinate positions before listing pairs.Confusing inverse with complement.
R⁻¹reverses the three selected pairs.Rᶜremoves those pairs and keeps the other three inA×B. Write the verbs "reverse" and "remove" beside the symbols.Using the wrong universe or counting duplicates. Box
U=A×Bbefore subtraction. Remember that a set ignores listing order and repeated entries, then finish with a cardinality check.
How exams test the idea, then the short version
Common question forms ask you to list a product, decide whether a displayed set is a valid relation, compute an inverse or complement, apply the mn and 2^(mn) cardinality rules, or verify an identity such as (R⁻¹)⁻¹=R.
Use the same order under time pressure: write the product universe, copy the selected relation, then perform the requested operation. For an inverse, reverse only the selected pairs. For a complement, keep the coordinate order and cross out the selected pairs. Finally, compare cardinalities with the size of the product. This short routine prevents a notation error from spreading through the answer.
The core rules are:
A×Bcontains every allowed ordered pair.Rselects some of those pairs.R⁻¹reverses the selected pairs intoB×A.Rᶜkeeps the unselected pairs in the declared universe.
For the next step, use the Engineering Mathematics for GATE course for structured mathematics study. The GATE Guidance course gives a broader preparation route, while the GATE CS category lets you compare the live course options.
Keep learning
Cartesian Product, Relation, Inverse and Complement MCQs: 10 Solved Questions
Solve 10 live Cartesian product and relation questions with concise working for relation counts, complements, composition, ordering and no-repetition strings.
Set Operations and Cartesian Product MCQs: 12 Solved Relational Algebra Questions
Solve 12 relational algebra MCQs on Cartesian products, set difference, identities, referential integrity, aggregation and division. Each answer shows the decisive reasoning step.
Set Operations and Cartesian Product in Relational Algebra: Worked Examples and Exam Traps
Learn when relational set operations are legal, calculate exact union and difference results, enumerate a Cartesian product, and trace how a join filters it.
Set Operations & Cartesian Product MCQs: 12 Solved Questions with Explanations
Solve 12 carefully explained MCQs on union, intersection, set difference, identities, counting, Cartesian products, and ordered set pairs.





