Similar questions 2 more → · asked again: GATE 2012, Q37
Sets, Relations & Functions

Answer & solution
Official answer: 36
There are 34 total functions. Exclude functions omitting at least one codomain value by inclusion-exclusion: 34−C(3, 1)24+C(3, 2)14=81−48+3=36. Equivalently choose the repeated pair of domain elements in 6 ways, its image in 3 ways and assign the other two images in 2 ways.
There are 3⁴=81 functions in total. For each of the three codomain elements, 2⁴=16 functions omit it. Subtract 3·16, then restore the three intersections where only one codomain element is used. The result is 81−48+3=36. Equivalently, an onto function must have fiber sizes 2, 1, 1: choose the repeated pair in C(4, 2)=6 ways, its image in 3 ways and assign the remaining two images in 2 ways. Both counts give 36.