GATE-style DBMS Problems Explained
By the end of this lesson you will have solved ten exam-style problems that cover the most frequently tested DBMS topics, and you will have a short method for each type. Every problem here is original. Try each one yourself before reading the solution; the method matters more than the answer.
How to use this lesson
GATE DBMS questions reward a fixed method more than clever insight. For each problem type below you get: the problem, a numbered method, and a worked solution. If a step feels unfamiliar, the linked lesson explains it fully. A good plan is to cover the solution with your hand, solve the problem on paper, then check.
Problem 1: counting super keys
R(A, B, C, D, E) has exactly two candidate keys: {A, B} and {B, C}. How many super keys does R have?
Method (from Keys): count supersets of each key and subtract the overlap.
Supersets of {A, B}: the other 3 attributes are free → 2^3 = 8
Supersets of {B, C}: 2^3 = 8
Supersets of {A, B, C}: counted twice → 2^2 = 4
Super keys = 8 + 8 − 4 = 12Answer: 12.
Problem 2: finding candidate keys
R(P, Q, R, S, T, U) with F = { P → Q, QR → S, S → P, T → U }. Find all candidate keys.
Method (from Attribute Closure & Canonical Cover):
- Attributes never on a right side must be in every key: R and T.
- (RT)⁺ = {R, T, U}. Not a key, so add one more attribute at a time.
(PRT)⁺: P → Q, QR → S, T → U = {P, Q, R, S, T, U} key
(QRT)⁺: QR → S, S → P, T → U = all key
(SRT)⁺: S → P, P → Q, T → U = all key
(URT)⁺: = {R, T, U} not a keyAnswer: PRT, QRT and RST. P, Q and S form a cycle (P → Q, QR → S, S → P), so each can play the same role.
Problem 3: highest normal form
Continue with R and F from Problem 2. What is the highest normal form?
Method (from Normal Forms: 1NF, 2NF & 3NF): list prime attributes, then look for a partial dependency of a non-prime attribute.
Prime: P, Q, R, S, T Non-prime: U
T → U: T is part of key PRT, and U is non-prime → partial dependencyAnswer: 1NF (not 2NF).
Problem 4: 3NF but not BCNF
R(A, B, C, D) with F = { A → B, B → A, AC → D }. Highest normal form?
Keys: C is never on a right side. (AC)⁺ = {A, B, C, D}, (BC)⁺ = {A, B, C, D}
Candidate keys: AC, BC Prime: A, B, C Non-prime: D
AC → D: AC is a super key fine for BCNF
A → B: A is not a super key, but B is prime allowed in 3NF, breaks BCNF
B → A: same reasoningAnswer: 3NF (see BCNF, 4NF & 5NF).
Problem 5: lossless join
R(A, B, C, D, E) with F = { A → B, C → D, AC → E }. Is the decomposition {AB, CD, ACE} lossless? Is {AB, CDE} lossless?
Method (from Lossless Join & Dependency Preservation): join two pieces at a time and check the common attributes.
{AB, CD, ACE}:
AB ⋈ ACE: common = {A}, A → B, so A is a key of AB lossless → ABCE
ABCE ⋈ CD: common = {C}, C → D, so C is a key of CD lossless → ABCDE
LOSSLESS (and each FD sits inside one piece, so dependencies are preserved too)
{AB, CDE}:
common = {} (no shared attribute) LOSSYAnswer: {AB, CD, ACE} is lossless; {AB, CDE} is not.
Problem 6: conflict serialisability
Schedule S: R1(X) R2(Y) R3(Z) W2(Y) R1(Y) W3(Z) R2(Z). Is S conflict serialisable? How many serial schedules is it conflict equivalent to?
Method (from Schedules, Serialisability & Recoverability): find conflicting pairs, draw edges, look for cycles, count topological orders.
On Y: W2(Y) before R1(Y) → T2 → T1
On Z: W3(Z) before R2(Z) → T3 → T2
On X: only T1 touches X → no edge
Graph: T3 → T2 → T1 no cycle
Topological orders: only T3, T2, T1Answer: yes, conflict serialisable, equivalent to exactly 1 serial schedule (T3, T2, T1).
Problem 7: recoverability
Classify W1(A) R2(A) W2(B) C2 C1 and W1(A) R2(A) W2(B) C1 C2.
Both: T2 reads A written by uncommitted T1 (a dirty read) → not cascadeless, not strict
First: T2 commits before T1 → NOT recoverable
Second: T1 commits before T2 → recoverable (but cascading rollback is possible)Answer: the first is not recoverable; the second is recoverable but not cascadeless.
Problem 8: B+ tree order
Block size 4,096 bytes, search key 16 bytes, block pointer 8 bytes, record pointer 8 bytes. Find the maximum order of a B+ tree internal node and leaf node.
Method (from B-Trees, B+ Trees & Hashing):
Internal: 8p + 16(p − 1) ≤ 4096 → 24p ≤ 4112 → p = 171
Leaf: p_leaf(16 + 8) + 8 ≤ 4096 → 24 p_leaf ≤ 4088 → p_leaf = 170Answer: internal order 171, leaf order 170.
Problem 9: index block accesses
A file has 1,20,000 records of 120 bytes in 4,096-byte blocks (unspanned). A dense multilevel secondary index is built on a unique 12-byte field with 8-byte block pointers. How many block accesses does an equality search need? Compare with binary search on the data file if it were sorted on that field.
Method (from File Organisation & Indexing):
bfr = floor(4096 / 120) = 34 data blocks = ceil(120000 / 34) = 3,530
fo = floor(4096 / 20) = 204 index entries = 1,20,000 (dense)
Level 1 = ceil(120000 / 204) = 589 blocks
Level 2 = ceil(589 / 204) = 3 blocks
Level 3 = ceil(3 / 204) = 1 block
Search = 3 index levels + 1 data block = 4 accesses
Binary search on 3,530 sorted blocks = ceil(log2 3530) = 12 accessesAnswer: 4 block accesses with the multilevel index, against 12 for binary search.
Problem 10: predicting SQL results
GATE often shows a query and asks how many rows it returns. Two classic traps: outer joins and NOT IN with NULL.
Part (a): on the practice database, how many rows does this return? Every order has a customer, and exactly one customer (Divya) has no orders.
SELECT COUNT(*) AS result_rows
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id;result_rows ----------- 16 (1 row)
Reasoning: 15 orders each match one customer, giving 15 rows, plus 1 row for Divya with NULLs: 16.
Part (b): table blocked(id) holds 2, 5 and NULL. How many products have an ID not in that list?
CREATE TABLE blocked (id INTEGER);
INSERT INTO blocked VALUES (2), (5), (NULL);
SELECT COUNT(*) AS not_in_count
FROM products
WHERE product_id NOT IN (SELECT id FROM blocked);
SELECT COUNT(*) AS not_exists_count
FROM products p
WHERE NOT EXISTS (SELECT * FROM blocked b WHERE b.id = p.product_id);not_in_count ------------ 0 (1 row) not_exists_count ---------------- 10 (1 row)
You should see 0 and then 10. x NOT IN (2, 5, NULL) means x <> 2 AND x <> 5 AND x <> NULL. The last part is UNKNOWN for every x, so no row passes. NOT EXISTS ignores the NULL row, so it returns the 10 products whose ID is neither 2 nor 5. This is the three-valued logic from SQL: The Practical Side of DBMS.
A quick reference of methods
| Problem type | Fast method |
|---|---|
| Super key count | 2^(n − k) per key, inclusion-exclusion for several keys |
| Candidate keys | Start with attributes never on a right side, grow with closures |
| Normal form | Keys → prime attributes → check partial, then transitive, then BCNF |
| Lossless join | Common attributes must determine one whole piece |
| Conflict serialisable | Precedence graph, no cycle, count topological orders |
| Recoverable | Reader must commit after the writer it read from |
| B+ tree order | Fill one block: pointers + keys ≤ block size |
| Index accesses | Levels = repeated ceil(entries / fo) until 1, plus 1 data access |
Common mistakes
- Rounding the wrong way. Orders and blocking factors use floor; block counts and levels use ceil.
- Ignoring other candidate keys. A normal form check must use every key to know which attributes are prime.
- Forgetting the data block. Index searches cost index levels plus one data access.
- Assuming NOT IN and NOT EXISTS always agree. They differ when the subquery returns NULL.
Key points
- Most DBMS exam problems follow a fixed method; practise the method, not the answer.
- Closure is the key tool for keys, FD implication, normal forms and lossless checks.
- Precedence graphs answer serialisability; commit order answers recoverability.
- Block arithmetic: floor for how many fit, ceil for how many are needed.
- Read SQL questions for NULLs and outer joins before counting rows.
Exercise
Solve this on your own: R(V, W, X, Y, Z) with F = { VW → X, X → Y, Y → V, Z → W }. (a) Find all candidate keys. (b) Find the highest normal form. (c) How many super keys does R have?
Show solution
(a) Z never appears on a right side. Z⁺ = {Z, W}.
(VZ)⁺: Z → W, VW → X, X → Y = all key
(XZ)⁺: X → Y, Y → V, Z → W = all key
(YZ)⁺: Y → V, Z → W, VW → X = all key
(WZ)⁺ = {W, Z} not a key
Candidate keys: VZ, XZ, YZ
(b) Prime: V, X, Y, Z. Non-prime: W.
Z → W: Z is part of key VZ and W is non-prime → partial dependency. Highest: 1NF
(c) Super keys contain Z plus at least one of V, X, Y; W is free.
Subsets of {V, X, Y} that are non-empty: 2^3 − 1 = 7; W in or out: × 2
Super keys = 14Check (c) another way: every super key contains Z, so count subsets of {V, W, X, Y} that include at least one of V, X, Y: 16 − 2 = 14 (the 2 excluded subsets are {} and {W}).
Quick Quiz
1. R has 6 attributes and one candidate key of 2 attributes. How many super keys?
The other 4 attributes are each in or out: 2^4 = 16.
2. In the precedence graph T1 → T2, T1 → T3 (no other edges), how many conflict-equivalent serial schedules exist?
T1 must come first; T2 and T3 can follow in either order.
3. Which rounding gives a B+ tree's order?
The order is the largest whole number of pointers that fits in the block.
4. SELECT * FROM t WHERE x NOT IN (SELECT y FROM s) returns no rows even though t is not empty. A likely cause is:
A NULL in the list makes every NOT IN comparison UNKNOWN.
Learn DBMS with a mentor
Free lessons get you started. Our Computer Science Fundamentals training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
