4. Measuring Performance: Time and Space
When evaluating an algorithm, we look at two main resources it consumes:
1. Time Complexity (Execution Time)
This refers to how long an algorithm takes to run relative to the size of the input, 'N'. We don't measure time in seconds because that depends on the computer's CPU speed. Instead, we count the number of operations performed.
2. Space Complexity (Memory Usage)
This refers to the amount of memory (RAM) an algorithm requires to run, also relative to the input size 'N'. This includes the memory needed to store the input and any temporary variables or data structures created during execution.
The Goal
The goal of algorithm design is often to minimize both time and space complexity, although sometimes there is a trade-off (e.g., using more memory to save execution time).