CS FundamentalsHardGATE CS (PYQ pattern)

R(A, B) = {(1,2), (1,3), (2,3), (3,4), (4,1)} is a graph's edge set. How many tuples are in the relation π_{A,D}(ρ(R) ⋈_{R.B = R2.A} ρ(R2)), i.e. the pairs reachable by paths of EXACTLY two edges (R2 is a copy of R with attributes renamed to (A, D))?

  1. A. 6
  2. B. 7
  3. C. 5
  4. D. 16

Correct answer: A. 6

Joining each edge (a,b) with the edge starting at b gives the two-edge paths [(1, 3), (1, 4), (2, 4), (3, 1), (4, 2), (4, 3)]; duplicates (a,d) are removed by the projection, leaving 6.

More DBMS and SQL questions

Exams that ask this topic