CS Atlas GATE 2027
DBMS course
0 / 119 complete

DBMS/Phase 4 · FDs & Normalization

Lesson 4.2.3 · Item 63 of 119

Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Read at your own pace. Try the questions before opening the answers.

On this page

0 · Recall Warm-up

Answer from memory first. Answers are in the Answer Vault at the bottom.

  1. Does AB → C imply A → C? from Lesson 4.2.2
  2. R has candidate keys {A} and {B} and 4 attributes. How many superkeys? from Lesson 2.2.1
  3. When is K a superkey in FD terms? from Lesson 4.2.1

1 · The Hook

"R(A, B, C, D, E) with F = {A → B, B → C, CD → E}. Find all candidate keys." This is probably the single most frequent normalisation question in GATE, and it feeds every normal-form question. One algorithm, the closure X⁺, solves it in a minute.

2 · Predict First

With F = {A → B, B → C, CD → E}, what does A determine? What does AD determine?

Make a guess in your head. The answer opens Section 3.

3 · Core Concept

Predict First — the answer

A → B → C, so A⁺ = ABC. AD: A gives B, C; then CD → E: AD⁺ = ABCDE, everything. So AD is a superkey.

Attribute closure X⁺

X⁺ = the set of all attributes that X determines under F.

Algorithm:

  1. Start: result = X.
  2. Repeat: for each FD L → R in F, if L ⊆ result, add R to result.
  3. Stop when a full pass adds nothing.

F implies X → Y exactly when Y ⊆ X⁺. X is a superkey exactly when X⁺ = all attributes of R.

Finding all candidate keys

  1. Must-have attributes: attributes that never appear on any right side must be in every key (nothing can determine them). Call this set M.
  2. Never-in-key attributes: attributes that appear only on right sides (never on a left side) are determined by others and are in no key (unless needed... they never are, because some left side determines them).
  3. Compute M⁺. If it is everything, M is the only candidate key.
  4. Otherwise add attributes from the remaining "both sides" group, smallest combinations first: M + 1 attribute, then M + 2, … Keep a set if its closure is everything and it contains no key already found.

Example 1

R(A, B, C, D, E), F = {A → B, B → C, CD → E}. Right sides: B, C, E. Never on the right: A, D → M = AD. AD⁺ = ABCDE. Only key: AD.

Example 2

R(A, B, C, D), F = {AB → C, C → D, D → A}. Right sides: C, D, A. Never on the right: B. B⁺ = B. Try B + one: AB⁺ = ABCD ✓, BC⁺ = BCDA ✓, BD⁺ = BDAC ✓. Keys: AB, BC, BD.

Example 3

R(A, B, C, D, E, F), F = {AB → C, C → D, D → E, E → F, F → A}. Must-have: B. AB, BC, BD, BE, BF all have full closure (each starts the chain to A). Five keys.

Prime and non-prime attributes

  • Prime: belongs to at least one candidate key.
  • Non-prime: belongs to none.

Example 1: prime A, D; non-prime B, C, E. Example 2: all of A, B, C, D are prime.

Counting superkeys (from Lesson 2.2.1)

Once the keys are known, count supersets with inclusion–exclusion. Example 3: a superkey must contain B and at least one of A, C, D, E, F: 2⁵ − 1 = 31.

4 · Visual

Closure of AD under  A->B, B->C, CD->E

start          AD
A->B  fires    ABD
B->C  fires    ABCD
CD->E fires    ABCDE      = all attributes  -> AD is a superkey
no more changes; AD has no smaller superkey (A+ = ABC, D+ = D) -> candidate key

5 · Worked Examples

Example 1 Easy

R(A, B, C, D), F = {A → B, B → C, C → D}. Find A⁺, B⁺ and the candidate keys.

Solution

A⁺ = ABCD, B⁺ = BCD. A never appears on a right side and A⁺ is everything: only key A.

Example 2 Medium

R(A, B, C, D, E), F = {AB → C, C → D, D → B, D → E}. Find all candidate keys and the prime attributes.

Solution

Never on the right: A. A⁺ = A. AB⁺ = ABCDE ✓, AC⁺ = ACDBE ✓, AD⁺ = ADBEC ✓, AE⁺ = AE. Keys: AB, AC, AD. Prime: A, B, C, D; non-prime: E.

Example 3 GATE

R(A, B, C, D, E, F), F = {A → B, B → C, C → A, D → E}. How many candidate keys, and how many superkeys?

Solution

Never on the right: D, F. DF⁺ = DFE. Add one of A, B, C (each determines all three): ADF, BDF, CDF: 3 keys. Superkeys: must contain D and F and at least one of A, B, C; E is free: (2³ − 1) × 2 = 14.

6 · GATE Traps

  • Attributes that are never on a right side are in every key; start from them.
  • An attribute only on right sides is in no key.
  • After finding a key, skip its supersets: they are not minimal.
  • Prime means "in some key", not "in the primary key".
  • Closure must be repeated until nothing changes; one pass is not enough.

7 · Memory Hook

"Never on the right? You're in every key. Only on the right? You're in none."

8 · Connect the Dots

Lesson 4.2.2 gave the rules; this lesson turned them into the closure algorithm and found all keys. Next: closure of a whole set of FDs, testing whether an FD is implied, and checking whether two FD sets say the same thing.

9 · Self-Test

GATE format. Try every question before opening the vault.

Q1 · NAT · 1 mark(s) — Closure

R(A, B, C, D, E), F = {A → C, C → D, B → E}. How many attributes are in A⁺?

Numerical answer: ________

Q2 · NAT · 2 mark(s) — Candidate keys

R(A, B, C, D, E, F), F = {AB → C, C → D, D → E, E → F, F → A}. How many candidate keys?

Numerical answer: ________

Q3 · MCQ · 2 mark(s) — Candidate keys

R(A, B, C, D, E), F = {A → B, BC → E, ED → A}. The candidate keys are:

  1. (A) ACD only
  2. (B) ACD, BCD, CDE
  3. (C) CD only
  4. (D) ABCD

Q4 · NAT · 2 mark(s) — Superkeys

R(A, B, C, D), F = {AB → C, C → D, D → A}. How many superkeys?

Numerical answer: ________

Q5 · MSQ · 2 mark(s) — Prime attributes

R(A, B, C, D, E), F = {A → B, B → C, CD → E}. Which attributes are prime?

  1. (A) E
  2. (B) D
  3. (C) A
  4. (D) B

10 · Rule Card

  • X⁺: start with X; add R for each L → R with L ⊆ result; repeat until no change.
  • F ⊨ X → Y ⇔ Y ⊆ X⁺; X superkey ⇔ X⁺ = R.
  • Keys: never-on-right attributes are in every key; only-on-right attributes in none; grow from the must-have set, smallest first, skip supersets of found keys.
  • Prime = in some candidate key; non-prime = in none.
  • Count superkeys with inclusion–exclusion over the keys.

11 · Concept Ledger

Unlocked in this lesson. From here on, these terms may be used.

attribute closure X⁺closure algorithmmust-have attributesfinding all candidate keysprime attributenon-prime attribute

12 · Answer Vault

Reveal answers when you’re ready

Recall Warm-up

  1. No; the left side cannot be split.
  2. 8 + 8 − 4 = 12.
  3. When K → all attributes of R.

Self-Test

Q1 Answer: 3 · 1 mark(s)

A⁺ = ACD.

Re-read: Lesson 4.2.3 — Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Q2 Answer: 5 · 2 mark(s)

AB, BC, BD, BE, BF.

Re-read: Lesson 4.2.3 — Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Q3 Answer: (B) · 2 mark(s)

C and D never appear on the right. CD⁺ = CD. ACD⁺, BCD⁺ and CDE⁺ are all ABCDE.

  • (A) is wrong: BCD and CDE also work.
  • (C) is wrong: CD alone determines nothing.
  • (D) is wrong: Not minimal.

Re-read: Lesson 4.2.3 — Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Q4 Answer: 7 · 2 mark(s)

Keys AB, BC, BD: 4 + 4 + 4 − 2 − 2 − 2 + 1 = 7.

Re-read: Lesson 4.2.3 — Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Q5 Answer: (B) (C) · 2 mark(s)

The only key is AD.

  • (A) is wrong: Not in any key.
  • (D) is wrong: Not in any key.

Re-read: Lesson 4.2.3 — Attribute closure; all candidate keys; prime vs non-prime; counting superkeys

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.