When we say an algorithm takes O(n) time, what is n?
Options
- The input size, like the number of items (Correct option)
- The number of lines of code in the program
- The number of CPU cores that the machine has
- The number of programmers on the dev team
Answer
The size of the input, for example the number of items in the list
Why
Big-O describes how the work grows as the input grows. n is the input size.
O(n) means that if the list becomes 10 times longer, the work becomes about 10 times bigger.
O(n²) would be about 100 times bigger, and O(1) would stay the same.
Remember
n = size of the input.