Explain the difference between time complexity and space complexity in the context of algorithm analysis, and provide an example algorithm where optimizing one may lead to a trade-off with the other.


Explain the difference between time complexity and space complexity in the context of algorithm analysis, and provide an example algorithm where optimizing one may lead to a trade-off with the other.