- $f$ has exactly one discontinuity.
- $f$ has exactly two discontinuities.
- $f$ has infinitely many discontinuities.
- $f$ is continuous.
I know theorems related to connectedness and continuity but I don't seem to incorporate them here in solving the problem. Can you suggest me how to approach this problem?
I claim that this $f$ is continuous. Take a $\xi\in S\setminus\{1,2\}$. Assume that $$\sigma:=\sup_{x\in S, \>x<\xi}f(x)<f(\xi)\ .$$ Then there is an $\eta$ with $\sigma<\eta<f(\xi)$. It follows that $f(S)$ can be partitioned into the two relatively open sets $f(S)\cap{\mathbb R}_{<\eta}$ and $f(S)\cap{\mathbb R}_{>\eta}$, contradicting the assumption about $f(S)$. It follows that in fact $$\sigma=f(\xi)\ .$$ (The same argument also shows that $\sup_{x\in S, \>x<1}f(x)=f(2)$, but this is not relevant for the continuity of $f$.)
Let an $\epsilon>0$ be given. Then there is an $x_0<\xi$ with $$f(\xi)-\epsilon=\sigma-\epsilon<f(x_0)<f(x)<f(\xi)\qquad(x_0<x<\xi)\ .$$ As $\epsilon>0$ was arbitrary this proves $\lim_{x\to \xi-} f(x)=f(\xi)$.
In a similar way one proves that $\lim_{x\to \xi+} f(x)=f(\xi)$ for all $\xi\in S\setminus\{3\}$.
Since all required one-sided limits have the proper value the function $f$ is indeed continuous on $S$.