CS FundamentalsVery hardGATE CS
Ed(a, b) = (1, 2), (1, 3), (2, 4), (3, 4), (4, 5), (4, 6), (5, 7), (6, 7), (2, 5) is a directed acyclic graph. The query WITH RECURSIVE R(n) AS (SELECT 1 UNION ALL SELECT b FROM Ed JOIN R ON Ed.a = R.n) SELECT COUNT(*) FROM R returns how many rows? (UNION ALL keeps duplicates; each row of R is one path from node 1.)
- A. 15
- B. 7
- C. 18
- D. 13
Correct answer: A. 15
With UNION ALL every distinct path from node 1 yields a row (paths to node 7 are numerous because the graph has diamonds), giving 15. With UNION the rows would be deduplicated to the 7 reachable nodes.
More DBMS and SQL questions
- O(cust, item) = (c1, x), (c1, x), (c1, y), (c2, z), (c2, NULL), (c3, NULL), (c3, NULL), (c4, w), (c4, w), (c5, p), (c5, q), (c5, p). How…
- R(x) = (1, 2, 2, 3, NULL, NULL, 5), S(x) = (2, 3, 3, NULL, 6), T(x) = (2, 2, 3, NULL, 5, 7) (one column each). How many rows does (SELECT…
- P(g, v) = (a, 5), (a, 7), (a, 7), (b, 3), (b, NULL), (b, 9), (c, 4), (c, 4), (d, NULL), (NULL, 1), (NULL, 2). How many rows does SELECT…
- T(g, v) = (g1, 5), (g1, 15), (g2, 8), (g2, 9), (g2, NULL), (g3, 50), (g4, NULL), (g4, NULL), (g5, 12), (g5, 3). How many groups does…
- Tk(s, c) = (s1, c1), (s1, c2), (s1, c3), (s2, c1), (s2, c2), (s3, c1), (s3, c2), (s3, c3), (s3, c4), (s4, c3), (s5, c2), (s5, c3), (s5…
- M(s) holds the scores 90, 85, 85, 80, 80, 80, 70, 70, 60. What is the sum over all nine rows of (RANK() OVER (ORDER BY s DESC)…