Big O Cheat Sheet: Master Performance Analysis

Joshua Sep 05, 2026

In the realm of computer science, data structures and algorithms are like the nuts and bolts of a machine, enabling efficient problem-solving. As such, understanding time complexity, often represented by Big O notation, is a fundamental skill for any programmer. But memorizing these complexities for various algorithms isn't feasible. Instead, let's master the concept with our comprehensive Big O Cheat Sheet. Here, we'll categorize algorithms into groups and delve into the intricacies of each.

Big-O Cheat Sheet Every Programmer Should Save
Big-O Cheat Sheet Every Programmer Should Save

First, let's revisit the concept of Big O. It's a notation used to describe the performance or complexity of an algorithm, measuring it against the increase in input size. It helps us understand the dominance of terms and constants, giving us an upper bound on the time complexity.

the big o cheat sheet is filled with different words
the big o cheat sheet is filled with different words

Constant Time Complexity (O(1))

Constant time algorithms have a time complexity that doesn't change with the addition of input data. Even if you increase the size of input, the running time remains the same.

Big-O [Cheat Sheet] Poster
Big-O [Cheat Sheet] Poster

Consider the act of accessing an element in an array using its index. Regardless of the array size, you can always access an element in constant time. This operation is represented as O(1). However, this doesn't account for the constant factors like memory access time or processor speed.

Example: Hash Maps and Dictionaries

the big - o notation poster is shown in blue and orange, with information on it
the big - o notation poster is shown in blue and orange, with information on it

Data structures like hash maps (or dictionaries in some languages) have a constant average time complexity for search, insert, and delete operations. Thanks to their efficient hash function, these operations can be performed without iterating through the entire data set.

Take the case of accessing an element in a Python dictionary. No matter how big the dictionary gets, the time it takes to retrieve an item is nearly constant, if a good hash function is used.

Example: Ternary Search

Big O - Cheat Sheet
Big O - Cheat Sheet

Ternary search is a divide-and conquer algorithm that splits the input array into three parts instead of two. While it's not as common as binary search, the time complexity remains O(log3 n), which can be approximated to O(1) for large inputs. This approximation is due to the log base 3 of a large number being close to 1.

Logged Time Complexities: O(log n)

Logged time complexity represents algorithms that divide the problem size in half with each step. This group includes binary searches, balanced trees (like AVL or Red-Black trees), and advanced algorithms like binary search trees (AVL, Red-Black trees, etc.).

Types of algorithms and algorithm examples
Types of algorithms and algorithm examples

We will not dig into each of these algorithms, but to put it simply, they partition the data and work on a subset. With each operation, the data set to work on is halved, thereby reducing the overall time complexity.

Example: Binary Search

Time Complexity Cheat Sheet for C++ & DSA | Big O Notation Explained
Time Complexity Cheat Sheet for C++ & DSA | Big O Notation Explained
the big - o compoxity chart is shown in this diagram
the big - o compoxity chart is shown in this diagram
Big O Notation Cheat Sheet by Assyrianic
Big O Notation Cheat Sheet by Assyrianic
Alex Xu (@alexxubyte) on X
Alex Xu (@alexxubyte) on X
Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell
Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell
the big - o comp is shown in this diagram, which shows how many people are
the big - o comp is shown in this diagram, which shows how many people are
an image of a computer screen showing the current data for different computers and their corresponding features
an image of a computer screen showing the current data for different computers and their corresponding features
Big-O Time Complexity ⏱️ DSA Cheat Sheet
Big-O Time Complexity ⏱️ DSA Cheat Sheet
a purple poster with the words markdown on it
a purple poster with the words markdown on it
Big O notation – leetcode cheat sheet
Big O notation – leetcode cheat sheet

Binary search is a classic example of O(log n) algorithm. In a sorted list, it finds the target value by repeatedly dividing the search interval in half. The time complexity of binary search is O(log n).

Here's a simple Python implementation: ```python def binary_search(arr, low, high, x): if high >= low: mid = (high + low) // 2 if arr[mid] == x: return mid elif arr[mid] > x: return binary_search(arr, low, mid - 1, x) else: return binary_search(arr, mid + 1, high, x) else: return -1 ```

Example: Height-Balanced Trees (AVL, Red-Black)

Height-balanced trees are binary search trees that balance operations, ensuring that the tree height is logarithmic. Since the tree is always balanced, insertions and deletions take place in O(log n) time.

The trick here is to rebalance the tree if it becomes unbalanced during insertions or deletions. This rebalancing can be done in O(log n) time, as only a few nodes need to be shifted.

Linear and Quadratic Time Complexities: O(n), O(n^2)

These are the most basic time complexities. Linear complexity, O(n), represents algorithms that visit each data item at least once. Bubble sort is an example of a linear time complexity algorithm.

Quadratic complexity, O(n^2), represents algorithms where each data item is visited approximately proportional to its position in the input size. Bubble sort, insertion sort, and selection sort fall into this category.

Linear and quadratic time complexities are not desirable for large data sets. Often, algorithms with lower time complexities are preferred, despite their increased upfront costs.

Example: Bubble Sort

Bubble sort repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. In the лучшем case scenario, it makes up to n passes through the list. Best, average, and worst-case time complexities of bubble sort are all O(n^2), making it inefficient on large lists.

Here's a Python implementation: ```python def bubble_sort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] ```

Example: Linked List Operations (Insertion, Deletion)

While searching an element in a linked list is O(n), insertion and deletion in a linked list can be done in O(1) time if the position of the node to be operated upon is known. However, finding the node might take O(n) operations since you might need to traverse the entire list.

Here's an example in Python: ```python class Node: def __init__(self, data=None): self.data = data self.next = None def insert begins(node, new_data): new_node = Node(new_data) new_node.next = node.next node.next = new_node def delete begins(node, key): temp = node if (temp is not None): if (temp.data == key): node = temp.next temp = None return while (temp is not None): if (temp.data == key): break prev = temp temp = temp.next if(temp == None): return prev.next = temp.next temp = None ```

To conclude, understanding Big O notation is the key to efficient programming. By knowing the time complexities of algorithms in your Big O arsenal, you can select the right tool for the job, ensuring that your code runs efficiently for all inputs, not just typical cases.

Always keep in mind that the goal is not to memorize these algorithms individually, but to understand the underlying computational resources and apply these principles in your coding journey. Happy coding!