Google Interview Question

Explain how you would optimize a basic algorithm and discuss its time and space complexity.