IAE Academy

GATE 2022 CS Q.25: solution and answer

GATE 2022 · CSQ.25 · 1 mark · MSQ

Consider the following three relations in a relational database.

, ,

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

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

Options (A) and (B) are correct.

Official answer: A, BSource: Official answer key, GATE 2022 CS (IIT Kharagpur)

  1. "Owns all brands" is a relational division: we want the employees such that for every brand in , the pair is in .

  2. (A) returns exactly the values that appear in paired with every of . Projecting on keeps the same set. Correct.

  3. (B) This is the textbook expansion of division. lists every (employee, brand) pair that would have to exist. Subtracting leaves the missing pairs. Projecting on gives the employees who lack at least one brand. Removing them from leaves the employees who own all brands. Correct.

  4. (C) The divisor is , the brands owned by someone, not all brands. If some brand in is owned by nobody, an employee who owns every owned brand is returned although he does not own all brands. Not correct in general.

  5. (D) The dividend pairs every owner with every owned brand, whatever that owner actually owns. Dividing by then only tests whether every brand is owned by somebody. If so, every owner is returned, including owners of a single brand. Not correct.

  6. So the expressions that always return the employees owning all brands are (A) and (B).

KEY IDEA

Owning all brands is relational division by . Division can be written directly (A) or expanded as "all owners minus owners with a missing (employee, brand) pair" (B).

WATCH OUT FOR

Dividing by (C) or building the dividend from owned brands only (D). Both compare against the brands that are owned, not against all brands in .

From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 13 Relational algebra questions, with notes

More Relational algebra questions