No. of surjective maps from a $n$ element set to a 3 element set I am calculating the number of surjective maps from a $n$  element set to a 3 element set in a different way from the usual inclusion-exclusion method : I have to distribute $n$ objects into 3 holes such that hole 1, hole 2 and hole 3  contains $i$, $j$ and $k$ objects respectively such that $i + j + k =n $. Now I vary $i$ and $j$ appropraitely.   
The expression 
$$ \sum_{i=1} ^ {n-2}  \sum_{j=1} ^ {n-i-1} {n \choose i}{n-i \choose j}  $$ is the answer. It is an alternative way to calculate the number of surjective maps. 
 A: Altogether, there are $3^n$ functions. Only constant maps and maps onto $2$-element subsets will fail to be surjective. There are $3$ constant maps. There are $3$ different $2$-element subsets, and given a $2$-element subset, there are $2^n$ total maps into it, so $2^n-2$ maps into and onto it. Thus, there are $$3^n-3-3(2^n-2)=3^n+3-3\cdot 2^n$$ surjective maps.

If you'd prefer to count them directly instead of indirectly through the complement, suppose we're mapping from an $n$-element set $X$ to the set $Y=\{x,y,z\}$. A map $f:X\to Y$ will be surjective precisely when $$\left\{f^{-1}(x),f^{-1}(y),f^{-1}(z)\right\}$$ is a partition of $X$.
Then we need $|f^{-1}(x)|=i$ and $|f^{-1}(y)|=j$ for some $i,j\ge 1$ such that $i+j<n.$ Since $j\ge1$, then $i+1\le i+j<n,$ so $i\le n-2$. Since $i+j<n,$ then $j\le n-1-i$. Once we've determined $f^{-1}(x)$ and $f^{-1}(y)$ meeting these conditions then, $f^{-1}(z)$ will be determined for us.
Given $1\le i\le n-2$, there are $\binom{n}{i}$ subsets of $X$ with cardinality $i$. Once we've chosen such a subset to be $f^{-1}(x)$, given any $1\le j\le n-1-i$, there are $\binom{n-i}{j}$ ways to choose a subset of $X$ disjoint from the first, having cardinality $j$, which we will let be $f^{-1}(y)$. Hence, your corrected formula $$\sum_{i=1}^{n-2}\sum_{j=1}^{n-1-i}\binom{n}{i}\binom{n-i}{j}$$ is indeed an alternate way to count the number of surjective maps.
