Attribute Sets

1 min read Updated Fri Apr 24 2026 07:36:29 GMT+0000 (Coordinated Universal Time)

A set of attributes.

Closure

Suppose XX is an attribute set and FF is a set of functional dependencies.

Closure of XX under a set of functional dependencies FF, is the set of all attributes functionally determined by XX using the dependencies in FF. Denoted as X+X^+,

Algorithm

X+X^+ can be computed by:

  1. Start with X+=XX^+ = X.
  2. For each dependency YZY \rightarrow Z in FF:
    If YX+Y \subseteq X^+, then add ZZ to X+X^+.
  3. Repeat until no new attributes can be added.

If X+X^+ includes all attributes of RR, then XX is a superkey of RR.

Can be used to test if a given functional dependency holds.

def attribute_closure(attributes, fds):
    """
    Compute the closure of a set of attributes with respect to a set of functional dependencies.

    :param attributes: set of attribute strings, e.g. {'A', 'B'}
    :param fds: list of tuples (lhs, rhs), where lhs and rhs are sets of attributes
                e.g. [({'A'}, {'B'}), ({'B'}, {'C'})]
    :return: set of attributes in the closure
    """
    closure = set(attributes)
    changed = True
    while changed:
        changed = False
        for lhs, rhs in fds:
            if lhs.issubset(closure) and not rhs.issubset(closure):
                closure.update(rhs)
                changed = True
    return closure