PYQ Vault

JEE Mains Maths · Relations and Functions

Counting Functions

Counting functions between finite sets: all functions, one-one functions, functions with conditions on some values, and onto functions by inclusion–exclusion.

Why this matters

Nineteen PYQs. Most count all functions or one-one functions, often after a condition fixes a few values; the rest count onto functions, which is the same as sharing distinct objects so that everyone gets at least one. Two ideas cover the page.

Concept 1 of 2: Counting all functions and one-one functions

From an mm-element set to an nn-element set, each of the mm elements chooses its image independently: nmn^m functions. For one-one, the choices shrink by one each time: n(n−1)⋯(n−m+1)n(n-1)\cdots(n-m+1). With a condition, count the choices for the constrained elements first, then multiply by the free choices of the rest. Many-one means all minus one-one.

Definition

  • All functions: nmn^m.
  • One-one: n!(n−m)!\frac{n!}{(n-m)!} (none if m>nm>n).
  • Many-one: nm−n!(n−m)!n^m-\frac{n!}{(n-m)!}.
  • Conditions: (choices for the constrained elements) ×\times (free choices).

One-one functions

n!(n−m)!=n(n−1)⋯(n−m+1)\frac{n!}{(n-m)!}=n(n-1)\cdots(n-m+1)

Worked example

How many one-one functions are there from {1,2,3}\{1,2,3\} to {a,b,c,d,e}\{a,b,c,d,e\}?
Practice this conceptself-check · 4 quick reps

The same idea in a real exam question:

JEE Mains · 2024 · 9 April 2024 · Q175Moderate

Example 1 · Relations and Functions · Counting Functions

Let A={(x,y):2x+3y=23,x,y∈N}\mathbf{A = \{(x,y):2x + 3y = 23,x,y \in N\}} and B={x:(x,y)∈A}\mathbf{B = \{ x:(x,y) \in A\}}. Then the number of one-one functions from AA to BB is equal to

More inputs than outputs

A one-one function needs at least as many outputs as inputs. From a larger set to a smaller one there are none.

Concept 2 of 2: Counting onto functions

Count all functions, then remove those that miss some output, by inclusion–exclusion: subtract those missing one named output, add back those missing two, and so on. For two outputs this is 2m−22^m-2; for three it is 3m−3⋅2m+33^m-3\cdot2^m+3. Giving mm distinct objects to nn people so that each gets at least one is the same count.

Definition

  • Onto: ∑j=0n(−1)j(nj)(n−j)m\sum_{j=0}^{n}(-1)^j\binom nj(n-j)^m.
  • n=2n=2: 2m−22^m-2. n=3n=3: 3m−3⋅2m+33^m-3\cdot2^m+3.
  • None if m<nm<n. Not onto = all − onto.

Onto functions

nm−(n1)(n−1)m+(n2)(n−2)m−⋯n^m-\binom n1(n-1)^m+\binom n2(n-2)^m-\cdots

Worked example

How many onto functions are there from a 5-element set to a 3-element set?
Practice this conceptself-check · 4 quick reps

The same idea in a real exam question:

JEE Mains · 2026 · 4 Apr 2026 Shift 1 · Q54Moderate

Example 2 · Relations and Functions · Counting Functions

The number of functions f:{1,2,3,4}→{a,b,c}\mathbf{f:\{ 1,2,3,4\} \rightarrow \{ a,b,c\}}, which are not onto, is :

Add back the double-counted

Subtracting 'misses aa' and 'misses bb' removes the functions that miss both twice. The +(n2)(n−2)m+\binom n2(n-2)^m term puts them back.

Summary — formulas & gotchas at a glance

A revision cheat-sheet for the formulas and gotchas above. Click any concept name to jump back to its full explanation.

Formulas (2)

Watch out for (2)

Test yourself on Relations and Functions

20 past JEE Mains questions from this chapter, timed at 48 minutes and marked the way the exam marks it. You see your score and every answer the moment you finish. Free to start.