How would you optimize a time-intensive algorithm to run on a mobile device without freezing the user interface?