CS FundamentalsVery hardGATE CS (PYQ pattern)
Edge table G(a, b): (1,2), (2,3), (3,1), (3,4), (4,5), (6,7). The recursive query WITH RECURSIVE R(x,y) AS (SELECT a,b FROM G UNION SELECT R.x, G.b FROM R JOIN G ON R.y = G.a) SELECT COUNT(*) FROM R counts all reachable pairs (x, y) in the transitive closure. What does it return?
- A. 15
- B. 17
- C. 20
- D. 6
Correct answer: B. 17
From 1, 2 and 3 (which form a cycle) one reaches 1, 2, 3, 4, 5 (5 pairs each = 15); from 4: only 5 (1 pair); from 6: only 7 (1 pair); plus nothing from 5 or 7. UNION removes duplicates, so the cycle terminates. Total 17.
More DBMS and SQL questions
- Table M(g, v): (x,10), (x,NULL), (x,20), (y,NULL), (y,NULL), (z,30). How many groups does SELECT g FROM M GROUP BY g HAVING COUNT() >…
- O(oid, c): (1,100), (2,100), (3,200), (4,NULL). I(oid, p, q): (1,5,2), (1,6,1), (2,5,3), (3,7,1), (3,7,1), (9,1,1). C(c, n): (100,u)…
- Transaction T1 executes R1(A), W1(A), R1(B) and T2 executes W2(A), R2(B), W2(B), each in the stated order (no commits modelled). Among all…
- Consider the schedule R2(X), W1(X), W2(X), W2(Y), C2, R1(Y), C1, W3(X), R3(X), C3 (Ci is the commit of Ti). Which is the strongest…
- Schedule S: R1(X), W2(X), W2(Y), W1(Y), W3(X), W3(Y), R3(Y). Which statement is correct?
- Basic timestamp ordering with TS(T1) < TS(T2) < TS(T3). A transaction aborts when it violates the rules, and once aborted its later…