A rule X -> Y says knowing X fixes Y. Computing the closure X+ tells you everything X determines — and whether it is a key.
A functional dependency X -> Y is a rule saying the columns in X *fix* the value of the columns in Y: any two rows that agree on X must agree on Y. FDs are the raw material of normalization and the way we discover keys.
Three rules are sound (they derive only true FDs) and complete (they can derive every FD that holds). Every closure step is really just these, applied quietly:
Y is a subset of X, then X -> Y. (A set determines its own parts.)X -> Y, then XZ -> YZ for any Z. (Add the same columns to both sides.)X -> Y and Y -> Z, then X -> Z. (Chaining.)The closure X+ is everything X determines: start with X, then keep adding the right-hand side of any FD whose left-hand side you already hold, until nothing new appears.
closure(X, F):
result = X
repeat until result stops growing:
for each FD L -> R in F:
if L is a subset of result:
result = result union R
return resultRelation R(A, B, C, D, E) with F = { A -> BC, CD -> E, B -> D, E -> A }. Compute {A}+:
start: {A}
A -> BC : {A, B, C}
B -> D : {A, B, C, D}
CD -> E : {A, B, C, D, E} (we now hold both C and D)
{A}+ = {A, B, C, D, E} = all attributes{A}+ is every column, A alone identifies any row — so A is a superkey, and since a single-column set has nothing to remove, it is a candidate key. Running the same computation, {E}+ is also all attributes (E -> A -> BC ...), so E is a second candidate key.A set is a superkey exactly when its closure is every column. A candidate key is a superkey with no removable column. To find them, test small sets first and never grow a set that is already a superkey.
R(A,B,C,D) with F = { A -> B, B -> C, C -> D }, what is {A}+?