sajad torkamani

Time complexity is a measure of how much time the algorithm will require to execute relative to the input size. Time complexity will be affected by things like how many for loops you use.

Space complexity is a measure of how much memory space the algorithm will require relative to the input size. Space complexity will be affected by things like what data structures you use (e.g., primitives use less space than arrays) or how many new variables you create.

Depending on your program, you might care more about one than the other. For example, if you’re writing a program that needs to run on a small embedded device and that runs very infrequently, low memory requirements may be more important than execution time.