Optimal Approximation with Sparse Neural Networks and Applications