Skip to main content

GATE CSE 2019Databases › Relational Algebra & CalculusVerified

GATE CSE 2019 PYQ: Consider the following relations P ( X , Y , Z ) , Q ( X , Y , T ) P(X,Y,Z), Q(X,Y,T) P ( X , Y , Z ) , Q (…

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: ________

    Answer

    1

    Approach

    Evaluate the two relational-algebra expressions separately. Each is a join of two tables, filtered by a conjunction of predicates, then projected onto X. Because projection is a set operation, duplicate X values collapse; the final result is the set difference of the two projected sets, and the asked quantity is its cardinality.

    The first projection contributes the single value X2 and the second contributes the single value X1; removing the latter from the former leaves the one-element set {X2}. The number of tuples returned by the query is therefore 1.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.