Find the number of onto functions from set A (4 elements) to set B (3 elements)

medium JEE-MAIN JEE Main 2022 3 min read

Question

Find the number of onto (surjective) functions from a set AA with 4 elements to a set BB with 3 elements.

(JEE Main 2022)


Solution — Step by Step

Total number of functions from AA to BB: each of the 4 elements in AA can map to any of the 3 elements in BB. So total =34=81= 3^4 = 81.

An onto function must “hit” every element of BB. We need to subtract functions that miss at least one element of BB.

Let AiA_i = set of functions that miss element bib_i from BB.

We want: A1cA2cA3c=|A_1^c \cap A_2^c \cap A_3^c| = Total A1A2A3- |A_1 \cup A_2 \cup A_3|

By inclusion-exclusion:

A1A2A3=AiAiAj+A1A2A3|A_1 \cup A_2 \cup A_3| = \sum|A_i| - \sum|A_i \cap A_j| + |A_1 \cap A_2 \cap A_3|

Ai|A_i| = functions missing one specific element = 24=162^4 = 16. There are (31)=3\binom{3}{1} = 3 such terms.

AiAj|A_i \cap A_j| = functions missing two specific elements = 14=11^4 = 1. There are (32)=3\binom{3}{2} = 3 such terms.

A1A2A3|A_1 \cap A_2 \cap A_3| = functions missing all three elements = 04=00^4 = 0.

A1A2A3=3(16)3(1)+0=483=45|A_1 \cup A_2 \cup A_3| = 3(16) - 3(1) + 0 = 48 - 3 = 45
Onto functions=8145=36\text{Onto functions} = 81 - 45 = \mathbf{36}

Why This Works

A function from AA to BB is onto if every element of BB is the image of at least one element of AA. Since A=4>B=3|A| = 4 > |B| = 3, onto functions exist (they wouldn’t if A<B|A| < |B|).

The inclusion-exclusion principle handles the “at least one element missed” condition systematically. Directly counting onto functions is hard, but counting functions that miss specific elements is easy — if we exclude kk elements from BB, the remaining (3k)(3-k) elements give (3k)4(3-k)^4 functions.


Alternative Method — Using the formula directly

The number of onto functions from a set of mm elements to a set of nn elements (mnm \geq n) is:

k=0n(1)k(nk)(nk)m\sum_{k=0}^{n} (-1)^k \binom{n}{k} (n-k)^m

For m=4m = 4, n=3n = 3:

(30)(3)4(31)(2)4+(32)(1)4(33)(0)4\binom{3}{0}(3)^4 - \binom{3}{1}(2)^4 + \binom{3}{2}(1)^4 - \binom{3}{3}(0)^4 =8148+30=36= 81 - 48 + 3 - 0 = 36

This formula is worth memorising for JEE. For small values, you can also use: onto functions from mm to nn = n!×S(m,n)n! \times S(m, n) where S(m,n)S(m, n) is the Stirling number of the second kind. For S(4,3)S(4, 3): partition 4 elements into 3 non-empty groups = 6 ways, then assign to 3 elements of BB = 6×3!=366 \times 3! = 36.


Common Mistake

A frequent error is computing 343×24=8148=333^4 - 3 \times 2^4 = 81 - 48 = 33 and stopping there — forgetting the inclusion-exclusion correction for double-counting. When we subtract functions missing b1b_1, missing b2b_2, and missing b3b_3, we over-subtract functions that miss TWO elements (they get subtracted twice). We must add those back. Always complete all terms of inclusion-exclusion.

Want to master this topic?

Read the complete guide with more examples and exam tips.

Go to full topic guide →

Try These Next