Sub topic 19
Minimal Cover of a Set of FDs
This chapter assumes you can compute attribute closure and know that a set of functional dependencies (FDs) F implies another FD when the closure test succeeds. A minimal cover is a simplified set of FDs that is equivalent to F. You need it for 3NF synthesis and for GATE questions that ask you to simplify FDs.
What a minimal cover is
Two FD sets are equivalent when each implies every FD in the other. A minimal cover (also called a canonical cover) of F is an equivalent set Fc that satisfies three conditions:
- Every FD in Fc has a single attribute on the right side.
- No FD has an extraneous attribute on its left side. Removing such an attribute would leave an equivalent set.
- No FD is redundant. Removing it would leave an equivalent set.
Some textbooks merge FDs with the same left side, so A -> B and A -> C become A -> BC. GATE questions usually keep the single-attribute form. State which form you are using.
The procedure
The steps must run in this order.
Step 1: split right sides
Replace X -> AB with X -> A and X -> B. This is valid by the decomposition rule. Drop duplicates.
Step 2: remove extraneous left-side attributes
Take an FD X -> A where X has more than one attribute. Attribute B in X is extraneous if A is in the closure of X - {B}, computed under the whole current set. If so, replace X -> A with (X - {B}) -> A.
The test only needs closure under the current set. It never needs the FD you are shrinking to be absent.
Step 3: remove redundant FDs
For each FD X -> A, compute the closure of X under all the other FDs. If A is in that closure, the FD is redundant. Delete it, and use the smaller set for later tests.
Worked example
Let R(A, B, C) have F = {A -> BC, B -> C, A -> B, AB -> C}.
Step 1. Split A -> BC. The set becomes A -> B, A -> C, B -> C, AB -> C. The second copy of A -> B is a duplicate and is dropped.
Step 2. Only AB -> C has a composite left side. The closure of {B} contains C, so A is extraneous. The FD becomes B -> C, which duplicates an existing FD. The set is now A -> B, A -> C, B -> C.
Step 3.
- A -> C: under {A -> B, B -> C} the closure of A is {A, B, C}, so A -> C is redundant. Remove it.
- A -> B: under {B -> C} the closure of A is {A}. Keep it.
- B -> C: under {A -> B} the closure of B is {B}. Keep it.
The minimal cover is {A -> B, B -> C}.
Computing it in code
The function below reuses the closure idea from the earlier chapter.
def closure(attrs, fds):
result = set(attrs)
changed = True
while changed:
changed = False
for lhs, rhs in fds:
if lhs <= result and not rhs <= result:
result |= rhs
changed = True
return result
def minimal_cover(fds):
# Step 1: single-attribute right sides, no duplicates
g = []
for lhs, rhs in fds:
for a in sorted(rhs):
fd = (frozenset(lhs), frozenset({a}))
if fd not in g:
g.append(fd)
# Step 2: remove extraneous left-side attributes
for i, (lhs, rhs) in enumerate(g):
lhs = set(lhs)
for b in sorted(lhs):
if len(lhs) > 1 and rhs <= closure(lhs - {b}, g):
lhs = lhs - {b}
g[i] = (frozenset(lhs), rhs)
unique = []
for fd in g:
if fd not in unique:
unique.append(fd)
g = unique
# Step 3: remove redundant FDs
i = 0
while i < len(g):
lhs, rhs = g[i]
rest = g[:i] + g[i + 1:]
if rhs <= closure(lhs, rest):
g = rest
else:
i += 1
return g
fds = [({'A'}, {'B', 'C'}), ({'B'}, {'C'}), ({'A'}, {'B'}), ({'A', 'B'}, {'C'})]
cover = minimal_cover(fds)
print(sorted((''.join(sorted(l)), ''.join(sorted(r))) for l, r in cover))
# [('A', 'B'), ('B', 'C')]The cover is not unique
The order in which you test attributes and FDs can change the result. Take F = {A -> B, B -> A, B -> C, A -> C, C -> A}. Both of these sets are minimal covers of F:
- {A -> B, B -> C, C -> A}, with 3 FDs.
- {A -> B, B -> A, A -> C, C -> A}, with 4 FDs.
So two minimal covers can differ in size. A question that asks for "the" minimal cover normally accepts any valid one, but a question that asks for the number of FDs may depend on the choice.
Where it is used
- 3NF synthesis. Compute a minimal cover, create one relation per distinct left side with all its right sides, add a relation for a candidate key if none is contained in a relation, and remove relations contained in others. This gives a lossless, dependency-preserving 3NF design.
- Equivalence checks. To test whether F and G are equivalent, check that every FD of one follows from the other by closure.
Common errors
- Testing for extraneous attributes with the closure under only the FD being shrunk, instead of the whole set.
- Skipping step 1 and then trying to judge redundancy with multi-attribute right sides.
- Removing two FDs that are each redundant only because of the other.
- Treating a single-attribute left side as possibly extraneous. It cannot lose its only attribute.
Exercise
Find a minimal cover of F = {A -> B, AB -> C, C -> A, C -> B} on R(A, B, C).
Show answer
Step 1 changes nothing, because every right side is already a single attribute. Step 2: in AB -> C, the closure of {A} under F is {A, B, C}, which contains C, so B is extraneous and the FD becomes A -> C. The set is now A -> B, A -> C, C -> A, C -> B. Step 3: C -> B is redundant, because under the others the closure of C is {C, A, B}. A -> C, A -> B and C -> A are each needed. One minimal cover is {A -> B, A -> C, C -> A}.
Exercise
Why is A extraneous in AB -> C when F also contains B -> C?
Show answer
The closure of {B} already contains C, so B alone determines C. Dropping A from the left side gives an FD that F already implies. F still implies the original AB -> C by augmentation, so the new set is equivalent.