AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Harddbmskeysclosure

~180s

Counting candidate keys

For R(A, B, C, D) with the functional dependencies AB → C, C → D and D → A, how many candidate keys does R have?

Show the answer and the worked solution

Correct answer: C.

3

Worked solution

  1. B never appears on the right of any dependency, so B belongs to every candidate key, and (B)+ is just B.
  2. (AB)+ gives C through AB → C and then D through C → D, covering all four attributes, so AB is a candidate key.
  3. (BC)+ gives D through C → D and then A through D → A, so BC is a candidate key.
  4. (BD)+ gives A through D → A and then C through AB → C, so BD is a candidate key.
  5. 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.

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.

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. 1
  2. 2
  3. 3
  4. 4
Show the answer and the worked solution

Correct answer: C. 3

Worked solution

  1. B never appears on the right of any dependency, so B belongs to every candidate key, and (B)+ is just B.
  2. (AB)+ gives C through AB → C and then D through C → D, covering all four attributes, so AB is a candidate key.
  3. (BC)+ gives D through C → D and then A through D → A, so BC is a candidate key.
  4. (BD)+ gives A through D → A and then C through AB → C, so BD is a candidate key.
  5. 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.

All OS, DBMS & Networks questions · placement mock tests