Prove that a continuous function $f:\mathbb R\to \mathbb R$ is injective if and only if it has no extrema I have a homework problem where I need to prove that a continuous function $f:\mathbb R\to \mathbb R$ is injective if and only if it has no extrema (local or global). 
So far what I have is:
We'll assume that $f$ is injective and assume that it has an extrema, $(x_{0}, f(x_{0}))$. Since $x_0$ is an extrema, there is a neighborhood of $x_0$ such that for each $x$ in the neighborhood, $f(x)\leq f(x_0)$ or $f(x)\geq f(x_0)$. This is where I got stuck. Intuitively I understand that that on each side of $x_0$, there have to be two points whose values are the same, which contradicts the assumption that $f$ is injective - I'm having extreme difficulty proving it, though.
If we assume that $f$ has no extrema, then I've tried to show that it is also a strictly monotonic function, but I'm having difficulty proving this as well.
I'd appreciate any help. 
 A: Assume $f$ is injective and has a local maximum at $x_0$ (the proof for local minimum is nearly the same).
Then there exists $\epsilon>0$ such that $|x-x_0|<\epsilon$ implies $f(x)\le f(x_0)$.
Let $x_1=x_0-\frac\epsilon2$, $x_2=x_0+\frac\epsilon2$.
Then $f(x_1)< f(x_0)$ and $f(x_2)< f(x_0)$ by injectivity.
If $f(x_1)<f(x_2)<f(x_0)$, then there exists a $\xi$ with $x_1<\xi<x_0$ and $f(\xi)=f(x_2)$ (intermediate value theorem). Since $\xi<x_0<x_2$, this contradicts injectivity.
Similarly, if $f(x_2)<f(x_1)<f(x_0)$, there exists a $\xi$ with $x_0<\xi<x_1$ and $f(\xi)=f(x_1)$. Since $x_1<x_0<\xi$, this contradicts injectivity.

For the other direction, assume that $f$ has no local extrema.
Let $x_1,x_2$ be two real numbers, wlog. $x_1<x_2$.
Then $f$ assumes its maximum and its minimum on the compact interval $[x_1,x_2]$. 
If the maximum is assumed at an inner point of the interval, that would be a local extremum.
Hence the maximum is assumed at $x_1$ or $x_2$.
Similarly, the minimum is assumed at $x_1$ or $x_2$.
If we assume $f(x_1)=f(x_2)=:c$, then $c$ is both minimum and maximum, i.e. $f$ is constant on $[x_1,x_2]$, thus making every inner point such as $\frac{x_1+x_2}2$ a local maximum (and minimum) - contradiction. Therefore, $f(x_1)\ne f(x_2)$.
