Continuity of function mapping connected set to connected set

If a function maps every connected set onto a connected set, is it necessarily continuous? I know the converse is true.

-

No. Consider $f: \mathbb{R} \to \mathbb{R}$ defined by

$$f(x) = \begin{cases} \left(\sin\frac{1}{ x}\right)&\text{if \;x> 0;}\\ \\ \quad\quad0 &\text{if x \leq 0.} \\ \end{cases}$$

Then you can see that $f$ is discontinuous at $x=0$.

-

No. For example, let $f:\mathbb R\to \mathbb R$ be defined by $f(x)=0$ if $x\leq 0$, and $f(x)=\sin\left(\frac1{x}\right)$ if $x>0$.

For functions defined on intervals in $\mathbb R$, this is the intermediate value property, a.k.a. Darboux property, after Darboux's theorem stating that derivatives have this property. E.g., $g(x)=x^2\sin(1/x)$, $g(0)=0$ is differentiable everywhere on $\mathbb R$, and its derivative is discontinuous, but still maps intervals to intervals.

There are even functions that map every open interval onto $\mathbb R$, like the Conway base 13 function.

For stronger results, see Characterising Continuous functions.

-

I assigned a question like this to my students recently. Being continuous in $\mathbb{R}$ is equivalent to the graph being path connected. This is because a path-connected graph is compact on each closed interval, which implies continuity (see Munkres topology).

-