How to test whether a function is one-one or onto, with the horizontal line test and algebra, and how restricting the domain or codomain fixes a function.
A function $f$ is one-one if different inputs always give different outputs. In symbols: $$f(a) = f(b) \implies a = b.$$
Horizontal line test. If some horizontal line $y = c$ cuts the graph more than once, then two inputs share the output $c$, so $f$ is not one-one. If no horizontal line does, $f$ is one-one.
For $f: A \to B$, the function is onto if the range equals the codomain, $f(A) = B$. Every element of $B$ must be the image of at least one element of $A$.
Note that "onto" depends on the codomain, but "one-one" does not. Changing the codomain to the range always makes a function onto.
A function that is both one-one and onto is a bijection. Only bijections have an inverse function (next lessons). A function that fails can often be repaired by restricting the domain or the codomain:
Example: Show that $f: \mathbb{R} \setminus {3} \to \mathbb{R} \setminus {2}$, $f(x) = \dfrac{2x + 1}{x - 3}$ is a bijection.
One-one. Suppose $f(a) = f(b)$. Then $(2a + 1)(b - 3) = (2b + 1)(a - 3)$. Expanding: $2ab - 6a + b - 3 = 2ab - 6b + a - 3$, so $-6a + b = -6b + a$, so $7b = 7a$ and $a = b$.
Onto. Let $y \in \mathbb{R} \setminus {2}$. Solving $y = \dfrac{2x+1}{x-3}$ gives $x(y - 2) = 3y + 1$, so $x = \dfrac{3y+1}{y-2}$, which is defined because $y \ne 2$. Also $x \ne 3$, since $x = 3$ would need $3y + 1 = 3y - 6$. So $x$ lies in the domain and $f(x) = y$.
Answer: $f$ is one-one and onto, so it is a bijection.
Example: $f(x) = x^2 - 4x$ on $\mathbb{R}$. Show it is not one-one and find the smallest $a$ for which $f$ is one-one on $[a, \infty)$.
$f(0) = 0$ and $f(4) = 0$, so two different inputs give the same output: not one-one. Write $f(x) = (x-2)^2 - 4$. The graph is symmetric about $x = 2$ and rising to the right of it. So on $[a, \infty)$ it is one-one exactly when $a \ge 2$.
Answer: not one-one on $\mathbb{R}$; the smallest such $a$ is $2$.
Exam tip: "Show that $f$ is one-one" needs an algebraic proof starting from $f(a) = f(b)$. A sketch alone does not earn full marks. For "not one-one" one explicit pair of inputs is the whole answer. State the codomain clearly when you discuss onto.