Answer
procedure onto $(x_1, x_2, x_3, ... x_n, y_1, y_2, y_3, ... y_m:$ the domain and co-domain of some function $f(x),$ respectively$)$
Define a new set representing a $m$ boolean values such that $b_i$ is true if and only if for some $x_{\alpha}, f(x_{\alpha}) = y_i$. {Initially, all $b_i :=$ false}
count $:= 0$
for $i:= 1$ to $n$
$\space\space\space$ curvalue $:= f(x_i)$
$\space\space\space$ if $b_{curvalue}$ is false
$\space\space\space$$\space\space\space$$\space\space\space$ count $:=$ count $+1$
$\space\space\space$$\space\space\space$$\space\space\space b_{curvalue}:=$ true
if count is equal to $m$ then return true
else return false
{true and false here refer to the status of function as onto}
Work Step by Step
This algorithm attempts to evaluate if a function is onto or not. To be onto, for every value $y$ in the co-domain, there must be an $x$ value such that $f(x) = y$. We check for this by first defining a set of boolean values as described above. These boolean values will allow us to know if we have encountered this value of the co-domain before or not.
We know a function is onto if we have m such incidents since the size of the co-domain is $m$.