In programming, you can optimize CPU performance or memory consumption, but not both. Most problems can be shifted to use more memory to gain speed, or more CPU time to use less memory, but you generally can't do both.