GATE CS 2024 Set 2 — Question 45

MCQ+2 / -0.67HardSelection & ProjectionRelational ModelDatabases

Databases → Relational Model → Selection & Projection

Last updated

Question

The relation schema, Person(pid, city), describes the city of residence for every person uniquely identified by pid. The following relational algebra operators are available: selection, projection, cross product, and rename.
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
A.
1
B.
2
C.
3
D.
4

Correct answer

(B) 2

Solution

To find cities with at least 3 persons, we need to find three distinct persons p1,p2,p3p_1, p_2, p_3 such that they all live in the same city.
In relational algebra, this is achieved by joining the Person relation with itself. Since only cross product (Cartesian product) is available (along with selection and projection), we perform the join manually.
We need 3 instances of the Person relation, say P1,P2,P3P_1, P_2, P_3.
1.Perform P1×P2P_1 \times P_2. This is the 1st cross product.
2.Perform (P1×P2)×P3(P_1 \times P_2) \times P_3. This is the 2nd cross product.
After obtaining P1×P2×P3P_1 \times P_2 \times P_3, we apply selection to ensure:
  • P1.city=P2.city=P3.cityP_1.city = P_2.city = P_3.city
  • P1.pidP2.pidP_1.pid \neq P_2.pid
  • P2.pidP3.pidP_2.pid \neq P_3.pid
  • P1.pidP3.pidP_1.pid \neq P_3.pid
Finally, we apply projection to get the city.
Since we need to combine 3 tables, we require 31=23 - 1 = 2 cross product operations.

More questions on Relational Model

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free