Data Structures & Algorithms Flashcards
What is Big O Notation?
A numeric representation of the efficiency of code
Big O Notation is a ____ way of talking about how efficient an algorithm is.
Generalized.
0(n)
Linear time complexity. The algorithm’s runtime increases linearly with the input size.
0(1)
Constant time complexity. The algorithm’s runtime is constant regardless of the input size.
0(n^2)
Quadratic time complexity. The algorithm’s runtime increases quadratically with the input size.
Time complexity describes…
how an algorithm’s performance scales as the size of the input increases.
Auxiliary space complexity…
refers to the amount of additional memory space required by an algorithm beyond the input size to solve a problem.
Rules of Thumb for space complexity:
1) Most primitives (booleans, numbers, undefined, null)….
2) Strings require ____ space …
3) Reference types are generally ____ space…
1) Take up constant space.
2) O(n)
space … where n is the string length.
3) O(n)
space … where n is the length (for array’s) or the number of keys (objects).
O(logN)
O(logN) time complexity, refers to a situation where the number of steps necessary to complete a task increases in proportion to the logarithm of the input size.
O(NLogN)
time complexity represents a scenario where the time an algorithm takes grows in proportion to N (the size of the input) multiplied by logN (the logarithm of N).
This complexity is seen in algorithms that perform a logarithmic operation multiple times, once for each element in the input.
O(2^N)
Represents exponential time complexity. Signifies that the execution time of an algorithm grows exponentially with the size of the input. For each additional element in the input, the execution time of the algorithm doubles.
What is a good example of an algorithm with exponential time complexity?
A common example of an algorithm with exponential time complexity is non-memoized recursion. In such cases, the algorithm often recalculates the same subproblems multiple times, leading to a dramatic increase in the number of operations.