Counting candidate keys — Aptitude Question
Counting candidate keys: For R(A, B, C, D) with the functional dependencies AB → C, C → D and D → A, how many… Answer and worked solution on CodeKairo.
- Topic: OS, DBMS & Networks
- Section: Programming MCQs
- Difficulty: Hard
- Time target: 180 seconds
Question
For R(A, B, C, D) with the functional dependencies AB → C, C → D and D → A, how many candidate keys does R have?
Options
- 1
- 2
- 3
- 4
Show the answer and the worked solution
Correct answer: C. 3
Worked solution
- B never appears on the right of any dependency, so B belongs to every candidate key, and (B)+ is just B.
- (AB)+ gives C through AB → C and then D through C → D, covering all four attributes, so AB is a candidate key.
- (BC)+ gives D through C → D and then A through D → A, so BC is a candidate key.
- (BD)+ gives A through D → A and then C through AB → C, so BD is a candidate key.
- No single attribute suffices and no other pair closes over everything, so R has 3 candidate keys.
Answer: 3.
The idea
Attributes on no right-hand side are in every key; attributes on no left-hand side are in none. Seeding the closure with the forced attributes cuts the search from every subset to a handful.
Shortcut. B cannot be derived, so pair it with each other attribute and take closures: AB, BC and BD each reach all of A, B, C, D, while B alone reaches nothing, giving 3.
Common trap. 1 stops at AB, the key visible on a left-hand side, without testing BC and BD.