GATE / CS ARCHIVE

GATE CSE 1992 / QUESTION 13(b)

Hotels serving a snack Rama likes

Database Management Systems · Relational Algebra & Calculus · Full GATE CSE 1992 paper

GATE 1992, Q13(b) Descriptive
Report issue

Relational Algebra & Calculus

Question 13(b), GATE 1992: Relations are FREQUENTS(CUSTOMER,HOTEL), SERVES(HOTEL,SNACKS), LIKES(CUSTOMER,SNACKS). They record visits, available snacks, and preferences respectively. Express in relational algebra the query: list hotels that serve a snack customer Rama likes.
Tap to enlarge
Answer & solution

Answer: π_HOTEL(SERVES ⋈ σ_CUSTOMER='Rama'(LIKES)). (no official key was published)

First select Rama's preferences: R = σ_CUSTOMER='Rama'(LIKES). Next match those snack names with served snacks by a natural join on their common attribute SNACKS. Finally discard the customer and snack columns, retaining only hotels:

π_HOTEL(SERVES ⋈ σ_CUSTOMER='Rama'(LIKES)).

An equivalent expression first projects preferences to snack names:
π_HOTEL(SERVES ⋈ π_SNACKS(σ_CUSTOMER='Rama'(LIKES))).

For any hotel h in this result, the join supplies some snack s with SERVES(h,s) and LIKES('Rama',s), exactly the requested existential condition. Conversely, every such pair joins and projects to h, so no qualifying hotel is omitted. Under ordinary set relational algebra projection removes duplicates when a hotel serves several liked snacks.

FREQUENTS is deliberately unused: the query does not require Rama to visit the hotel. Joining it and filtering Rama would incorrectly exclude unvisited hotels. Nor is division appropriate: division would express serving every liked snack, whereas the wording asks for at least one. If Rama likes no snacks, the result is empty.

Original paper, page 9