Quantum algorithms for machine learning and optimization