How to find no. of onto functions

Answers (1)
D Data type

If no. of elements in set A = m, and no. of elements in set B = n.

Then, If m\geq n, No. of onto functions from set A to set B = n^m-^nC_1(n-1)^m+^nC_2(n-2)^m-...

For eg. if mapping is done such that there are 5 balls to be put in 5 boxes, then no. of ways of putting, such that no box remains empty (No. of onto functions) = 3^5-^3C_12^5+^3C_21^5 = 150

If m<n, then no. of onto functions = 0