Prove $\big|\int_0^1f(x)dx-\frac{1}{n}\sum_{k=1}^{n} f(\frac{k}{n})\big|=O(\frac{1}{n})$ Let $f(x)$ be bounded ($|f(x)|\le M$) and monotonic function on $[0,1]$. Prove $$\big|\int_0^1f(x)dx-\frac{1}{n}\sum_{k=1}^{n} f(\frac{k}{n})\big|=O(\frac{1}{n})$$ My attempt: Let $\big|\int_0^1f(x)dx-\frac{1}{n}\sum_{k=1}^{n} f(\frac{k}{n})\big|=I$ hence $\exists$ $A > 0$ such that $|I|\le \frac{A}{n}$ hence 
$$n\cdot\big|\int_0^1f(x)dx-\frac{1}{n}\sum_{k=1}^{n} f(\frac{k}{n})\big|\le n\cdot\big|\int_0^1f(x)dx\big|+\big|\sum_{k=1}^{n} f(\frac{k}{n}) \big|\le n\cdot\big|\int_0^1f(x)dx\big|+\sum_{k=1}^{n}\big| f(\frac{k}{n}) \big|\le nM+nM=2nM\le A $$ hence $A=2nM$. Is that right?  I didn't use the fact that $f(x)$ is monotonic so I think I made a logical mistake somewhere. Please help because I can't figure that out
 A: Hint: This is just like the integral test in infinite series.  Let's work on the case where $f$ is monotonically increasing.
For fixed $n$, consider the interval $\left[\frac{a}{n},\frac{a+1}{n}\right]$.  Since $f$ is monotonic, $f\left(\frac{a}{n}\right)\leq f(x)\leq f\left(\frac{a+1}{n}\right)$ for $x\in\left[\frac{a}{n},\frac{a+1}{n}\right]$.
Hence, 
$$
\frac{1}{n}\cdot f\left(\frac{a}{n}\right)=\int_{\frac{a}{n}}^{\frac{a+1}{n}}f\left(\frac{a}{n}\right)dx\leq\int_{\frac{a}{n}}^{\frac{a+1}{n}}f(x)dx\leq\int_{\frac{a}{n}}^{\frac{a+1}{n}}f\left(\frac{a+1}{n}\right)dx=\frac{1}{n}\cdot f\left(\frac{a+1}{n}\right).
$$
Therefore, 
$$\int_0^1f(x)dx=\sum_{a=0}^{n-1}\int_{\frac{a}{n}}^{\frac{a+1}{n}}f(x)dx\leq\sum_{a=0}^{n-1}\frac{1}{n}\cdot f\left(\frac{a+1}{n}\right)=
\frac{1}{n}\sum_{a=1}^{n}f\left(\frac{a}{n}\right).
$$
On the other hand,
$$\int_0^1f(x)dx=\sum_{a=0}^{n-1}\int_{\frac{a}{n}}^{\frac{a+1}{n}}f(x)dx\geq\sum_{a=0}^{n-1}\frac{1}{n}\cdot f\left(\frac{a}{n}\right)=
\frac{1}{n}\sum_{a=0}^{n-1}f\left(\frac{a}{n}\right).
$$
The first inequality gives us
$$
\frac{1}{n}\sum_{a=1}^{n}f\left(\frac{a}{n}\right)-\int_0^1f(x)dx\geq 0
$$
The second inequality gives us
$$
\int_0^1f(x)dx-\frac{1}{n}\sum_{a=1}^{n}f\left(\frac{a}{n}\right)\geq\frac{1}{n}\sum_{a=0}^{n-1}f\left(\frac{a}{n}\right)-\frac{1}{n}\sum_{a=1}^{n}f\left(\frac{a}{n}\right)=\frac{1}{n}(f(0)-f(1))
$$
or that
$$
\frac{1}{n}\sum_{a=1}^{n}f\left(\frac{a}{n}\right)-\int_0^1f(x)dx\leq\frac{1}{n}(f(1)-f(0))\leq\frac{1}{n}\cdot 2M
$$
Hence, the difference is at most $\frac{2M}{n}=O\left(\frac{1}{n}\right)$.
