Complexity Flashcards
Time complexity
Is a measure of the amount of time it takes for an algorithm to run as function of the input size. It provides an estimate of how the algorithms runtime grows as the input size increases. It usually expresses by big O notation.
O(1)
Constant time. The algorithms runtime remains content regardless of the input size.
Example:
Accessing a specific index within an array: arr[0]
O(log n)
Logarithmic time. The algorithms runtime grows logarithmically with the input size.
Example: binary search tree
O(n)
Linear time. The algorithms runtime grows in direct proportion to the size of the input data.
Example: for loop
O(n log n)
Linearithmitic time. The algorithms runtime grows in proportion to the product of the input size and its logarithm.
Example: merge sort
O(n^2)
Quadratic time. The algorithms runtime grows quadratically with the input size.
Example: nested for loops
O(2^n)
Exponential time. The algorithms runtime grows exponentially with the input size.
Example: double recursive method