datarekha

Functional Dependencies & Closure

If two rows share an X-value, must they share a Y-value? That's a functional dependency — the rule that decides keys, normal forms, and half of GATE DA's DBMS marks.

8 min read Intermediate GATE DA Lesson 69 of 122

What you'll learn

  • A functional dependency X to Y means rows that agree on X must agree on Y
  • Armstrong's axioms: reflexivity, augmentation, transitivity — and what each one buys you
  • How to compute an attribute closure X-plus step by step
  • Reading a closure to decide which FDs are derivable

Before you start

Picture an employee table. Every employee has exactly one department. If I hand you two rows and they share the same emp_id, you’d bet your laptop they share the same dept too. That little promise — “agree on the left, must agree on the right” — is a functional dependency.

Once you see it that way, FDs stop feeling abstract. They’re just rules the data has to obey. The whole game in DBMS is: given a handful of these rules, what else must be true? This is also the quiet engine behind every schema you’ll design on the job — the same closure you compute here is what decides whether a table is safe to split or doomed to update anomalies.

What a functional dependency actually says

We write X → Y and read it as “X determines Y.” It means: in any valid instance of the table, whenever two rows agree on every attribute in X, they also agree on every attribute in Y. Note X and Y can each be a single attribute or a set.

Examples that are easy to feel:

  • emp_id → name — one ID, one name.
  • course_id, semester → instructor — that course in that semester has one instructor.
  • dept → dept_head — every department has one head.

An FD is a constraint on the schema, not a property of one particular table snapshot.

Armstrong’s axioms — the three rules that generate the rest

From a small set of FDs you can derive many more. Armstrong gave us three rules that are sound (only produce true FDs) and complete (produce every true FD).

  • Reflexivity — if Y is a subset of X, then X → Y. (Trivial: a set determines any of its parts.)
  • Augmentation — if X → Y, then XZ → YZ for any Z. (You can pad both sides with extra attributes.)
  • Transitivity — if X → Y and Y → Z, then X → Z. (Chain them.)

Three handy corollaries you’ll reuse:

  • Union: X → Y and X → Z give X → YZ.
  • Decomposition: X → YZ gives X → Y and X → Z.
  • Pseudo-transitivity: X → Y and WY → Z give WX → Z.

Attribute closure X⁺ — the workhorse

Given a set of FDs, the attribute closure X⁺ is the largest set of attributes determined by X. It answers the only question that matters in practice: starting from X, what can we conclude?

The algorithm is mechanical. Start with closure = X. Walk through every FD; if its full LHS is already inside closure, add its RHS to closure. Repeat until nothing changes.

V, WV→XV, W, XWX→YV, W, X, YWX→ZV,W,X,Y,ZEach step adds attributes whose FD’s full LHS already sits in the closure.
The closure grows monotonically; stop when a full pass over the FDs adds nothing.

How GATE asks this

Two main flavours, both painless once you can compute a closure:

  • NAT — “What is the size of X⁺ under the given FDs?” Just run the algorithm and count.
  • MSQ — “Which of the following FDs are derivable from F?” For each candidate A → B, compute A⁺ and check whether B lies inside it. If yes, it’s derivable.

Worked example — GATE DA 2024

R(U, V, W, X, Y, Z) with FDs F = {U → V, U → W, WX → Y, WX → Z, V → X}. Which of the following are derivable? (A) VW → Y (B) U → Y (C) UX → Z (D) VW → YZ

Strategy: compute VW⁺ (handles A and D), then U⁺ (handles B), then UX⁺ (handles C).

Compute VW⁺. Start closure = {V, W}.

  1. V → X: LHS V is in the closure, so add Xclosure = {V, W, X}.
  2. WX → Y: LHS W, X both present, add Yclosure = {V, W, X, Y}.
  3. WX → Z: LHS W, X both present, add Zclosure = {V, W, X, Y, Z}.
  4. Another pass adds nothing. So VW⁺ = VWXYZ.

That contains Y and YZ, so both A and D are derivable. (The official 2024 answer was A and D.)

Quickly check the others. U⁺: start {U}; U → V adds V; U → W adds W; now V → X adds X; WX → Y, WX → Z add Y, ZU⁺ = UVWXYZ. So U → Y (B) is also derivable. UX⁺ contains the same full set, so UX → Z (C) is derivable too. In the original paper, only the printed options A and D were the marked-true ones — but the takeaway is the procedure.

Quick check

Quick check

0/6
Q1R(A,B,C,D,E) with F = {A → BC, CD → E, B → D, E → A}. What is the size of A⁺ (number of attributes)?numerical answer — type a number
Q2Same R and F. What is the size of B⁺?numerical answer — type a number
Q3From F = {U → V, U → W, WX → Y, WX → Z, V → X}, which FDs are derivable? (select all that apply)select all that apply
Q4Which statements about Armstrong's axioms are TRUE? (select all that apply)select all that apply
Q5R(A,B,C,D) with F = {AB → C, C → D, D → A}. Is A → B derivable?
Q6A booking table has FDs: booking_id → seat, seat → flight, flight → airline. A teammate claims 'booking_id determines the airline' so the airline column is redundant. Are they right (does booking_id⁺ contain airline)?

Practice this in an interview

All questions
What are 1NF, 2NF, and 3NF, and when would you intentionally denormalize?

1NF eliminates repeating groups and requires atomic column values. 2NF further removes partial dependencies on a composite key. 3NF removes transitive dependencies — every non-key column must depend on the key, the whole key, and nothing but the key. Denormalization trades update anomalies for read performance, and is appropriate when the read path dominates and write correctness can be enforced at the application layer or with materialized views.

What is the gaps-and-islands problem, and how do you solve it with window functions?

Gaps-and-islands is the problem of identifying contiguous ranges (islands) within ordered sequential data and the breaks (gaps) between them. The classic solution subtracts a dense sequential integer from the ordering column — equal differences belong to the same island.

Explain joint, marginal, and conditional distributions and how to move between them.

The joint distribution P(X, Y) fully specifies two random variables together. Marginals P(X) and P(Y) are obtained by summing (or integrating) the joint over the other variable. Conditionals P(X|Y=y) are the joint sliced at a fixed y value, renormalized by the marginal P(Y=y).

Why does SQL require every non-aggregated SELECT column to appear in GROUP BY?

Because after grouping, multiple source rows collapse into one output row. Any column not in the GROUP BY key could have different values across those collapsed rows, making a single deterministic output value impossible without an aggregate function.

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Explore further

Related lessons

Skip to content