We have a function
f:N→N, defined as
f(1)=f(2)=1 and f(x)=x−1, for every x>2
For one-one :
Since, f(1)=f(2)=1, therefore 1 and 2 have same image, namely 1.
So, f is not one-one.
For onto :
y=1 has two pre-image, namely 1 and 2.
Now, let y∈N,y≠1 be any arbitrary elements.
Then, y=f(x)
⟹y=x−1⟹x=y+1>2 for every y∈N,y≠1.
Thus, for every y∈N,y≠1, there exists x=y+1 such that
f(x)=f(y+1)=y+1−1=y
Hence, f is onto.