Complexity

References: How to Find the Complexity of an Algorithm 1. Introduction Algorithmic complexity is a measure of the resources and algorithm requires about its input size. The two main types are: Time complexity: number of operations performed by an algorithm Space complexity: the amount of memory consumed 2. Time Complexity The time complexity of an algorithm quantifies the amount of time (operations) taken by an algorithm to run as a function of the length of the input It’s commonly expressed by Big-O notation Hierarchy of Time Complexities (Fastest to Slowest): (O(1)) - Constant: Fastest; performance is independent of input size. (O(\log n)) - Logarithmic: Very fast, typical for binary searches. (O(n)) - Linear: Efficient, grows proportionally to input. (O(n\log n)) - Linearithmic: Common for efficient sorting, like QuickSort. (O(n^{2})) - Quadratic: Acceptable for small input, common in nested loops. (O(2^{n})) or (O(n!)) - Exponential/Factorial: Generally only acceptable for very small inputs. 2.1. Constant Time - (O(1)) It takes the same amount of time regardless[rɪˈɡɑːrd.ləs] of input size. 2.2 Linear Time - (O(n)) [ˈlɪn.i.ɚ] ...

January 27, 2026 · 3 min · Phong Nguyen