Skip to content
Official PYQ · 2019

GATE CS 2019 Q55 — Relational Model: Relational Algebra

Explain with AI
Consider the following relations P(X,Y,Z),Q(X,Y,T)P(X,Y,Z), Q(X,Y,T) and R(Y,V)R(Y,V).
XYZX1Y1Z1X1Y1Z2X2Y2Z2X2Y4Z4Table: PXYTX2Y12X1Y25X1Y16X3Y31Table: QYVY1V1Y3V2Y2V3Y2V2Table: R\overset{\textbf{Table: P}}{\begin{array}{|l|l|l|} \hline \textbf{X} & \textbf{Y} & \textbf{Z} \\ \hline \text{X1} & \text{Y1} & \text{Z1} \\ \hline \text{X1} & \text{Y1} & \text{Z2} \\ \hline \text{X2} & \text{Y2} & \text{Z2} \\ \hline \text{X2} & \text{Y4} & \text{Z4} \\ \hline \end{array}} \qquad \overset{\textbf{Table: Q}}{\begin{array}{|l|l|l|} \hline \textbf{X} & \textbf{Y} & \textbf{T} \\ \hline \text{X2} & \text{Y1} & 2 \\ \hline \text{X1} & \text{Y2} & 5 \\ \hline \text{X1} & \text{Y1} & 6 \\ \hline \text{X3} & \text{Y3} & 1 \\ \hline \end{array}} \qquad \overset{\textbf{Table: R}}{\begin{array}{|l|l|} \hline \textbf{Y} & \textbf{V} \\ \hline \text{Y1} & \text{V1} \\ \hline \text{Y3} & \text{V2} \\ \hline \text{Y2} & \text{V3} \\ \hline \text{Y2} & \text{V2} \\ \hline \end{array}}
How many tuples will be returned by the following relational algebra query?

Πx(σ(P.Y=R.Y∧R.V=V2))(P×R))–Πx(σ(Q.Y=R.Y∧Q.T>2))(Q×R))\Pi_x (\sigma_{(P.Y=R.Y \wedge R.V=V2))} (P \times R)) – \Pi_x (\sigma_{(Q.Y = R.Y \wedge Q.T>2))} (Q \times R))

Answer: ________
View worked solution

Answer: 1

To find the number of tuples returned by the query, we evaluate the two parts of the set difference expression separately.

Part 1: T1=ΠX(σ(P.Y=R.Y∧R.V=′V2′)(P×R))T_1 = \Pi_X (\sigma_{(P.Y=R.Y \wedge R.V='V2')} (P \times R))

  • We first filter relation RR for V=V2V = \text{V2}: σV=′V2′(R)={(Y3,V2),(Y2,V2)}\sigma_{V='V2'}(R) = \{(\text{Y3}, \text{V2}), (\text{Y2}, \text{V2})\}.
  • Next, we join this result with PP on YY. The only matching tuple in PP with Y∈{Y2,Y3}Y \in \{\text{Y2}, \text{Y3}\} is (X2,Y2,Z2)(\text{X2}, \text{Y2}, \text{Z2}).
  • Projecting on XX gives: T1={X2}T_1 = \{\text{X2}\}.

Part 2: T2=ΠX(σ(Q.Y=R.Y∧Q.T>2)(Q×R))T_2 = \Pi_X (\sigma_{(Q.Y = R.Y \wedge Q.T > 2)} (Q \times R))

  • We first filter relation QQ for T>2T > 2: σT>2(Q)={(X1,Y2,5),(X1,Y1,6)}\sigma_{T>2}(Q) = \{(\text{X1}, \text{Y2}, 5), (\text{X1}, \text{Y1}, 6)\}.
  • We join these tuples with RR on YY. Since both Y=Y2Y = \text{Y2} and Y=Y1Y = \text{Y1} exist in RR, both tuples join successfully.
  • Projecting on XX gives: T2={X1}T_2 = \{\text{X1}\}.

Set Difference:

T1−T2={X2}−{X1}={X2}T_1 - T_2 = \{\text{X2}\} - \{\text{X1}\} = \{\text{X2}\}

The final relation contains exactly 1 tuple.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Relational Model: Relational Algebra questions