All Exams Test series for 1 year @ ₹349 only
Question

Consider a relational database schema with two relations $R(P, Q)$ and $S(X, Y)$.
Let $E = \{\langle u \rangle \mid \exists v\ \exists w\ \langle u, v \rangle \in R\ \land\ \langle v, w \rangle \in S\}$ be a tuple relational calculus expression.
Which one of the following relational algebraic expressions is equivalent to $E$ ?

The correct answer is
$\Pi_P (S \bowtie_{S.X = R.Q} R)$

Tuple Relational Calculus Analysis

The given tuple relational calculus (TRC) expression is:

$E = \{\langle u \rangle \mid \exists v\ \exists w\ \langle u, v \rangle \in R\ \land\ \langle v, w \rangle \in S\}$

With relations $R(P, Q)$ and $S(X, Y)$.

  • The condition $\langle u, v \rangle \in R$ means that $u$ corresponds to attribute $P$ and $v$ corresponds to attribute $Q$ in relation $R$. Thus, $u = R.P$ and $v = R.Q$.
  • The condition $\langle v, w \rangle \in S$ means that $v$ corresponds to attribute $X$ and $w$ corresponds to attribute $Y$ in relation $S$. Thus, $v = S.X$ and $w = S.Y$.
  • The existential quantifiers ($\exists v, \exists w$) indicate that we need to find matching tuples from $R$ and $S$, implying a join operation.
  • The common variable $v$ links the two relations. From $R$, $v = R.Q$. From $S$, $v = S.X$. This establishes the join condition: $R.Q = S.X$.
  • The expression $E$ selects $\langle u \rangle$, where $u$ is derived from $R.P$. Therefore, a projection on attribute $P$ is required from the result of the join.

Relational Algebra Equivalence

Combining the join condition ($R.Q = S.X$) and the projection on $P$, the equivalent relational algebra expression is:

$\Pi_{P} (R \bowtie_{R.Q = S.X} S)$

Join and Projection Match

Comparing this derived expression with the provided options:

  • Option 1: $\Pi_P (R \bowtie_{R.P = S.X} S)$ - The join condition $R.P = S.X$ is incorrect.
  • Option 2: $\Pi_P (S \bowtie_{S.X = R.Q} R)$ - The join condition $S.X = R.Q$ is equivalent to $R.Q = S.X$. The projection is on $P$. This expression matches the derived equivalent.
  • Option 3: $\Pi_P (R \bowtie_{R.P = S.Y} S)$ - The join condition $R.P = S.Y$ is incorrect.
  • Option 4: $\Pi_P (S \bowtie_{S.Y = R.Q} R)$ - The join condition $S.Y = R.Q$ is incorrect.

Option 2 correctly represents the equivalent relational algebraic expression.

Was this answer helpful?

Important Questions from Relational Algebra

  1. Consider the given relations $X$, $Y$ and $Z$. The relation $X$ has three columns $P$, $Q$ and $R$. The relation $Y$ has three columns $P$, $Q$ and $S$. The relation $Z$ has two columns $P$ and $T$. 

    Table X 

    PQR
    P1Q1R1
    P2Q2R2
    P3Q3R2

    Table Y 

    PQS
    P1Q12
    P1Q25
    P2Q16
    P3Q31

    Table Z 

    PT
    P1T1
    P3T2
    P4T3
    P4NULL

    Consider the relational algebra expression $$ \Pi_{P, R, S} \left[ \left( \sigma_{(Q = Q3 \lor R = R2)} [X \bowtie Y] \right) \bowtie \left( \sigma_{(S > 1)} [Y \bowtie Z] \right) \right] $$ where $\bowtie$ denotes natural join operation. 

    Which of the following options is the correct output for the given expression?

  2. Consider a database that includes the following relations: 

    Defender($name, rating, side, goals$) 

    Forward($name, rating, assists, goals$) 

    Team($name, club, price$) 

    Which ONE of the following relational algebra expressions checks that every name occurring in Team appears in either Defender or Forward, where $\phi$ denotes the empty set?

  3. Consider the following three relations:
    Car (model, year, serial, color)
    Make (maker, model)
    Own (owner, serial)
    A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. ($\bowtie$ denotes natural join)
    $ \pi_{\text{owner}} (\text{Own} \bowtie (\sigma_{\text{color}=\text{"red"}} (\text{Car} \bowtie (\sigma_{\text{maker}=\text{“ABC”}} \text{Make})))) $

  4. Consider the following tables, Loan and Borrower of a bank.
     

                         Loan          Borrower
    loan_numbranch_nameamountcustomer_nameloan_num
    L11Banjara Hills90000AnandL11
    L14Kondapur50000KarteekL11
    L15SR Nagar40000AnkitaL15
    L22SR Nagar25000GopalL19
    L23Balanagar80000KarteekL22
    L25Kondapur70000KarteekL23
    L19SR Nagar65000SunilL23
     SunilL25


    Query: $\pi_{\text{branch\_name}, \text{customer\_name}}(\mathbf{Loan} \bowtie \mathbf{Borrower}) \div \pi_{\text{branch\_name}}(\mathbf{Loan})$
    where $\bowtie$ denotes natural join.
    The number of tuples returned by the above relational algebra query is _______
    (Answer in integer)

  5. Consider the following three relations
    Employee (eid, eName), Comp(cid, cName), Own(eid, cid). Which of the following relational algebra expression return the set of eids who own all brands:

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App