Question

Consider the following three relations in a relational database.

Employee(eId,Name),Brand(bId,bName),Own(eId,bId)\text{Employee}(\text{eId}, \text{Name}), \quad \text{Brand}(\text{bId}, \text{bName}), \quad \text{Own}(\text{eId}, \text{bId})

Which of the following relational algebra expressions return the set of eIds who own all the brands?

Choose every correct option
Official answer and solution
Official answer
A and B
From
Official GATE 2022 answer key

Solution

Express the universal quantification condition 'owns all brands' using relational algebra division and its set-difference decomposition.

To find all eId who own all brands in relation Brand:

  1. Expression (A) computes ΠeId,bId(Own)/ΠbId(Brand)\Pi_{\text{eId}, \text{bId}}(\text{Own}) / \Pi_{\text{bId}}(\text{Brand}). Relational division R(A,B)/S(B)R(A, B) / S(B) returns the set of all AA-values that are associated in RR with every BB-value present in SS. Projecting eId yields precisely the employees who own all brands. Thus (A) is correct.
  2. Expression (B) uses the fundamental definition of division using projection, cartesian product, and difference:
    • ΠeId(Own)×ΠbId(Brand)\Pi_{\text{eId}}(\text{Own}) \times \Pi_{\text{bId}}(\text{Brand}) forms all possible pairs of (eId, brand) for each employee who owns at least one brand.
    • Subtracting ΠeId,bId(Own)\Pi_{\text{eId}, \text{bId}}(\text{Own}) yields the pairs (eId, brand) representing brands that an employee does NOT own.
    • Projecting on eId gives all employees who are missing at least one brand.
    • Subtracting this set from ΠeId(Own)\Pi_{\text{eId}}(\text{Own}) leaves only those employees who own all brands. Thus (B) is correct.
  3. Expressions (C) and (D) divide by ΠbId(Own)\Pi_{\text{bId}}(\text{Own}), which only considers brands currently owned by someone rather than all brands defined in the Brand relation.
Final answer

Options (A), (B)

Common trap

Dividing by ΠbId(Own)\Pi_{\text{bId}}(\text{Own}) instead of ΠbId(Brand)\Pi_{\text{bId}}(\text{Brand}), missing brands that are not yet owned by any employee.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2022 Computer Science and Information Technology (CS)
Question
25 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.