Finding upper and lower derivatives Let $$D^+f(x)=\lim\limits_{h \to 0}\left[\sup\limits_{0<|t|\leq h}\frac{f(x+t)-f(x)}{t}\right] \text{  and  } D^-f(x)=\lim\limits_{h \to 0}\left[\inf\limits_{0<|t|\leq h}\frac{f(x+t)-f(x)}{t}\right]$$ represent the upper and lower derivative respectively.
Let $f(x)=\begin{cases} x\sin(\frac{1}{x}) \text{ if } x \neq 0 \\ 0 \text{ if } x =0\end{cases}$ and $g(x)=\chi_{\mathbb{Q}}$.
My attempt at a solution:
If $x=0$, $D^+f(x)=0$ and $D^-f(x)=-\infty$.  If $x \neq 0$, then $D^+f(x)=\infty$ and $D^-f(x)=0$.
I believe the answer is similar to $g(x)$.
 A: $$D^+f(0)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{f(t)-f(0)}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{t\sin \frac1t}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\sin\frac{1}{t}$$
Now no matter how small $h$ gets, there always exist a point $t$ in $(0,h]$ so that
$\sin\frac{1}{t}=+1$ (take $t=\frac{1}{n\pi +\frac{\pi}{2}}$ for sufficiently large $n$)
Therefore, $D^+f(0)=+1$. Similarly $D^{-}f(0)=-1$.
At all points $x\neq 0$, $x\sin\frac{1}{x}$ is differentiable and as thus
$$D^+f(x)=D^-f(x)=f^{\prime}(x)=\sin \frac{1}{x}-\frac{1}{x}\cos\frac1x$$
For $g$: If $x\in \mathbb{Q}$,$$D^+g(x)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{g(x+t)-g(x)}{t}=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}$$
Now
$$\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}=\begin{cases}
0&\mbox{if } t\in \mathbb{Q}\\
\frac{-1}{t}&\mbox{if } t\notin \mathbb{Q}\end{cases}$$
The supremum is achieved when $t<0$ and $t\notin \mathbb{Q}$ which means $0<-t\le h\Rightarrow -h\le t<0$. No matter how small $h$ gets there always exists 
a point $t\in [-h,0)\cap \mathbb{Q}^c$ (density argument) and so
$$D^+g(x)=\lim_{h \to 0}\sup\limits_{0<|t|\leq h}\frac{\chi_{\mathbb{Q}}(x+t)-1}{t}=\lim_{h \to 0}\sup\limits_{-h\le t<0}\frac{-1}{t}=+\infty$$
All other cases are done in the same spirit
