Search

Search papers and lessons

Bijective Function

Level 1 · 10 min read

A bijective function pairs every input with exactly one output and reaches every output, so it can be undone without losing or inventing anything.

On this page

  • Colour = topic mix
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A bijective function is a Function that is both injective and surjective. Different inputs always give different outputs, and every element of the target set is reached by some input. Because of this, the function pairs the two sets off perfectly, with nothing left over on either side, and it can be reversed without losing or inventing anything.

Builds on: Injective Function, Surjective Function · Leads to: Graph Isomorphism, composing bijections

Where it's used

Seats and tickets. A cinema with 120 seats sells 120 tickets, and each ticket names one seat. If each seat is taken by exactly one ticket holder, the rule "ticket to seat" is bijective. Nobody shares a seat, and no seat is empty when the house is full. Each ticket and each seat can be matched with exactly one partner, and that matching is what the word "bijection" describes.

Encryption. A block cipher such as AES encrypts 128-bit blocks. For a fixed key, the encryption rule is a bijection on the set of 128-bit blocks. It must be: if two different blocks encrypted to the same output, decryption could not tell which one was meant. Decryption is the inverse bijection, and it returns the original block exactly.

Comparing graphs. Two drawings of a network may look different but have the same shape. They are isomorphic when there is a bijection between the nodes of one and the nodes of the other that keeps every connection. The Graph Isomorphism problem asks whether such a bijection exists. A bijection that maps nodes to nodes and edges to edges is the proof that two graphs are the same structure in different clothes.

How it works

Take two small sets: A={1,2,3}A = \{1, 2, 3\} and B={x,y,z}B = \{x, y, z\}. Let ff send the inputs as follows: f(1)=yf(1) = y, f(2)=zf(2) = z and f(3)=xf(3) = x.

  1. Write the outputs down. They are yy, zz and xx. Each input has exactly one output, so ff is a Function from AA to BB.
  2. Check that the outputs are all different. yy, zz and xx are three distinct elements. So no two inputs share an output, and ff is injective. Check: the output zz can only have come from 22.
  3. Check that every element of BB appears. xx, yy and zz all appear in the list of outputs. So ff is surjective. Check: no element of BB is left out.
  4. Both checks pass, so ff is bijective. Each element of AA is paired with exactly one element of BB, and the pairs use up both sets completely.
  5. Read the pairs backwards to get the inverse. From yy we go back to 11, from zz back to 22, and from xx back to 33. Check: applying the backward rule and then ff returns the start, for example f(1)=yf(1) = y and going back from yy gives 11 again.

Here is the same pairing as a diagram. Each input has exactly one arrow leaving it, and each output has exactly one arrow arriving.

flowchart LR
  i1[1] --> oy[y]
  i2[2] --> oz[z]
  i3[3] --> ox[x]

Now change the target set to B′={x,y,z,w}B' = \{x, y, z, w\}, with the same rule. The rule is still injective, since the outputs are still different, but it fails step 3: ww is never an output. So the function is not bijective. Some element of the target has no partner, so the pairing is incomplete. A bijection needs both checks to pass.

The picture version of the same idea uses a graph. For f(x)=x3f(x) = x^3 on the real numbers, every horizontal line hits the curve exactly once. A horizontal line that meets the graph once for every height is the picture of injective and surjective at once.

−2−1.5−1−0.500.511.52−505xf(x)
  • f(x) = x³
Every horizontal line meets this curve exactly once, so x³ is bijective from the real numbers to the real numbers.

The math

The arrow →\to reads "maps to". A Function f:A→Bf : A \to B is bijective when both of the following hold.

Definition: Bijective function

A function f:A→Bf : A \to B is bijective, or a bijection, if it is injective and surjective:

(injective)f(a)=f(a′)  ⟹  a=a′for all a,a′∈A,\text{(injective)} \quad f(a) = f(a') \implies a = a' \quad \text{for all } a, a' \in A,(surjective)for every b∈B there is some a∈A with f(a)=b.\text{(surjective)} \quad \text{for every } b \in B \text{ there is some } a \in A \text{ with } f(a) = b.

Here aa and a′a' are inputs, bb is an output, and   ⟹  \implies means "then". The first line says that different inputs never share an output. The second says that every element of BB is reached. Together they say that ff pairs each element of AA with exactly one element of BB, and each element of BB with exactly one element of AA. Formally, ff is the set of pairs (a,f(a))(a, f(a)) for aa in AA, a subset of the Cartesian product A×BA \times B.

An equivalent statement is that ff has an inverse: a function g:B→Ag : B \to A such that g(f(a))=ag(f(a)) = a for every aa in AA, and f(g(b))=bf(g(b)) = b for every bb in BB. Reading the pairs backwards gives gg. The inverse is written f−1f^{-1}.

Step 2 in symbols

For the rule above, f(1)=yf(1) = y, f(2)=zf(2) = z and f(3)=xf(3) = x. The three outputs are distinct:

f(1)≠f(2),f(1)≠f(3),f(2)≠f(3).f(1) \neq f(2), \qquad f(1) \neq f(3), \qquad f(2) \neq f(3).

So the injective condition holds.

Step 3 in symbols

For each element of BB we need an input. The three elements of BB are matched as follows:

x=f(3),y=f(1),z=f(2).x = f(3), \qquad y = f(1), \qquad z = f(2).

Every element of BB is hit, so the surjective condition holds.

Step 5 in symbols

The inverse is f−1(x)=3f^{-1}(x) = 3, f−1(y)=1f^{-1}(y) = 1 and f−1(z)=2f^{-1}(z) = 2. Check one of them: f(f−1(z))=f(2)=zf(f^{-1}(z)) = f(2) = z. Going forwards and then backwards gives back the start, as the definition of an inverse requires.

A counting fact

If f:A→Bf : A \to B is a bijection and both sets are finite, then AA and BB have the same number of elements. Injectivity alone forces ∣A∣≤∣B∣|A| \leq |B|, because each input needs its own output. Surjectivity alone forces ∣A∣≥∣B∣|A| \geq |B|, because each output needs its own input. Both together give equality. This is why a bijection is the right tool for saying that two sets have the same size.

Worked examples

Example
1. A tiny pairing of three elements

Let A={1,2,3}A = \{1, 2, 3\}, B={x,y,z}B = \{x, y, z\} and f(1)=zf(1) = z, f(2)=xf(2) = x, f(3)=yf(3) = y.

  1. List the outputs: zz, xx, yy. Three different outputs, so ff is injective.
  2. The outputs cover xx, yy and zz, so ff is surjective.
  3. Both checks pass, so ff is bijective.
  4. The inverse reads the pairs backwards: f−1(z)=1f^{-1}(z) = 1, f−1(x)=2f^{-1}(x) = 2, f−1(y)=3f^{-1}(y) = 3.

Interpretation: a bijection between two three-element sets is a relabelling. Each element of AA is simply given a new name from BB, and nothing is lost in the renaming.

Example
2. A linear rule on the real numbers

Let f(x)=2x+3f(x) = 2x + 3 from the real numbers to the real numbers. We show that ff is bijective.

  1. Injective: suppose f(a)=f(b)f(a) = f(b). Then 2a+3=2b+32a + 3 = 2b + 3. Subtract 33 to get 2a=2b2a = 2b, then divide by 22 to get a=ba = b. So ff is injective.
  2. Surjective: take any real number yy, and set x=y−32x = \frac{y - 3}{2}. Then f(x)=2⋅y−32+3=(y−3)+3=yf(x) = 2 \cdot \frac{y - 3}{2} + 3 = (y - 3) + 3 = y. So every real yy is an output.
  3. Both checks pass, so ff is bijective.
  4. The inverse is f−1(y)=y−32f^{-1}(y) = \frac{y - 3}{2}, which is the formula we used in step 2.

Interpretation: a straight line with a non-zero slope is a bijection of the real numbers onto themselves, and the inverse is found by solving the equation for xx.

Example
3. Tickets for a theatre with a broken seat

A theatre has 120 seats and sells one ticket for each seat, numbered 1 to 120. The rule "ticket to seat" is a bijection: each ticket names one seat, every seat is someone's, and nothing is left over.

  1. Now a seat is damaged and closed. There are 119 usable seats, but 120 tickets still exist.
  2. Try to give every ticket its own seat. The first 119 tickets can each take one usable seat. Ticket number 120 has nowhere to go, so the rule is not surjective onto the seats, or it sends two tickets to one seat. Either way it is not a bijection.
  3. The counting fact from the math section gives the same answer directly. A bijection between a set of 120 and a set of 119 cannot exist, because the two sizes differ.
  4. The theatre must either sell 119 tickets or reopen the broken seat.

Try it: the theatre reopens the seat, so there are 120 usable seats again. A usher assigns ticket nn to seat 121−n121 - n. Is this a bijection? Answer: yes. The rule is injective, since different tickets go to different seats. It is surjective, since every seat from 1 to 120 is reached by the ticket 121−n121 - n for some nn in 1 to 120. It is also a bijection with inverse f−1(s)=121−sf^{-1}(s) = 121 - s.

Common mistakes and tradeoffs

"One-to-one" means bijective. It is tempting to read "one-to-one" as the whole story. In fact many texts use "one-to-one" for injective alone, and "onto" for surjective alone. Bijective is the stronger word: it needs both. The map f(n)=3nf(n) = 3n from the whole numbers to the whole numbers is one-to-one, but it never produces 11, so it is not onto and not a bijection.

Equal size of input and output sets is enough. It is tempting to think that a function between two sets of the same size must be bijective. In fact, equal size only makes a bijection possible between finite sets. It does not force one, so the function must still be checked. Take A={1,2,3}A = \{1, 2, 3\} and B={a,b,c}B = \{a, b, c\} with f(1)=af(1) = a, f(2)=af(2) = a and f(3)=bf(3) = b. Both sets have three elements, but cc is never reached and aa is reached twice. The equal count only tells you a bijection is possible, not that this rule is one.

The domain matters. It is tempting to ask whether x2x^2 is bijective, as if the formula decided it. In fact it depends on the sets. x2x^2 from the real numbers to the real numbers is neither injective nor surjective, since 22 and −2-2 share the output 44 and negative numbers are never outputs. But x2x^2 from the non-negative real numbers to the non-negative real numbers is bijective: the inverse is the square root. Always state the domain and the codomain.

When to use it. Use a bijection when you need an exact pairing with nothing lost and nothing left over: a relabelling, a reversible encoding, or a proof that two sets have the same size. When only one of the two properties matters, use injective (no collisions, for example in identifiers) or surjective (full coverage, for example in a list of possible labels). You need a bijection specifically when you want an inverse that works in both directions.

History

The idea of matching two sets element by element is very old. What changed in the 1870s was its use for infinite sets. Georg Cantor asked whether the set of all whole numbers and the set of all rational numbers had the same size, and he found that a pairing between them existed, so they did. He then went further and showed that some infinite sets cannot be paired with the whole numbers at all. A pairing that uses up both sets completely was the test he trusted.

The names "injection", "surjection" and "bijection" were introduced by the Bourbaki group of French mathematicians in the 1930s and 1940s, as part of their effort to rewrite mathematics in terms of sets and functions. Naming the three cases made it easy to state each property on its own. The vocabulary caught on because it applies to any sets at all.

Recap

  • A Function gives each input exactly one output.
  • Injective means no two inputs share an output. Surjective means every element of the target is an output.
  • Bijective means both, so the function pairs the two sets exactly, with nothing left over.
  • A bijection has an inverse, and between finite sets it forces the two sets to have the same size.
  • Bijectivity depends on the domain and codomain as well as the formula.

Next, read about Graph Isomorphism, where a bijection between nodes that preserves connections defines when two graphs are the same shape. For chaining bijections together, see Function Composition. The composition of two bijections is again a bijection.

Check yourself

QuestionLet f:{1,2,3}→{a,b,c}f : \{1, 2, 3\} \to \{a, b, c\} with f(1)=bf(1) = b, f(2)=af(2) = a and f(3)=bf(3) = b. Is ff bijective?Show answer

No. The outputs are bb, aa and bb. The element cc is never an output, so ff is not surjective. Also, inputs 11 and 33 share the output bb, so ff is not injective either. A bijection needs both properties, and this rule has neither.

QuestionFor f(x)=4x−1f(x) = 4x - 1 on the real numbers, find f−1(y)f^{-1}(y) and check that f(f−1(y))=yf(f^{-1}(y)) = y for y=7y = 7.Show answer

Set y=4x−1y = 4x - 1 and solve for xx: add 11 to get 4x=y+14x = y + 1, then divide by 44 to get x=y+14x = \frac{y + 1}{4}. So f−1(y)=y+14f^{-1}(y) = \frac{y + 1}{4}. For y=7y = 7, f−1(7)=84=2f^{-1}(7) = \frac{8}{4} = 2. Check: f(2)=4⋅2−1=7f(2) = 4 \cdot 2 - 1 = 7. The inverse returns the original input.

QuestionWhy does a bijection between two finite sets force them to have the same number of elements?Show answer

Injectivity means each input uses its own output, so the input set is no larger than the output set. Surjectivity means each output has at least one input, so the output set is no larger than the input set. Both inequalities together give equality.

QuestionA school gives every student a locker number, and every locker belongs to exactly one student. A new student arrives, but there are no spare lockers. Explain in terms of bijection why the school cannot give the new student a locker without changing something.Show answer

The current rule "student to locker" is a bijection between the students and the lockers. Adding a student makes the set of students larger than the set of lockers. No function can be injective from a larger set into a smaller one, since two students would have to share a locker. So the rule stops being a bijection, and the school must either add a locker or accept that the pairing is no longer one-to-one.

Sources