Skip to main content

Big O Notation (Javascript)

Big O notation is a way of describing the efficiency of an algorithm. It describes how the runtime of an algorithm grows as the input size grows.

Some examples of Big O notation:

  • O(1) : Constant time - no matter the input size, the time taken is always the same.
  • O(n) : Linear time - the time taken grows linearly with the input size.
  • O(n^2) : Quadratic time - the time grows quadratically with the input size.
  • O(log n) : Logarithmic time - the time grows logarithmically with the input size. Example: Binary search.
  • O(n * log n): When an O(n) operation is performed on an O(log n) operation. Example: Sorting algorithms like merge sort.