Repaso
Español
Algorithms & DSFoundationsALG-55

When we say an algorithm takes O(n) time, what is n?

Options

  1. The input size, like the number of items (Correct option)
  2. The number of lines of code in the program
  3. The number of CPU cores that the machine has
  4. 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.

Key terms

Practice this question in Repaso