Suppose your are given a finite set $P$ of $n$ points $(x_i,y_i)$ with $x_0< x_1 <\ldots < x_n$. Denote by $f_P$ the function given by piecewise linear joining of these points.
Now suppose you are given $k<n$. I feel the following problem must have a well known algorithmic solution, but I am unable to use the right keywords to find it.
Given $k$, find a subset $S \subseteq P$ containing the endpoints with $|S|=k$, such that $f_S$ is the best fit to $f_P$ in eithter L1 or L2 sense i.e. such that
$$\int_{x_0}^{x_n} |f_P(x)-f_S(x)| dx $$ or $$ \int_{x_0}^{x_n} (f_P(x)-f_S(x))^2 dx $$
is minimal.
How are these optimization problems called? Are there fast algorithms. Does it help if you knew that $f_P$ had special properties. E.g. monotone or convex?
Let me add that in the application I have in mind $k$ is rather small compared to $n$, maybe something like 10 to 10000.