Show 45 more cards
Or learn them all in the app
O(n²)
quadratic time: usually two nested loops over the input
Bubble sort; comparing every pair of elements.
O(2ⁿ)
exponential time: the cost doubles with each extra input element
Trying every subset of a set.
O(n!)
factorial time: trying every possible ordering
Brute-force solution to the traveling salesman problem.
Big-Omega (Ω)
a lower bound on growth: the algorithm takes at least this long
Big-Theta (Θ)
a tight bound: growth is bounded above and below by the same function
Amortized analysis
the average cost per operation over a long sequence, even if a few operations are expensive
Appending to a dynamic array is amortized O(1).
Space complexity
how much extra memory an algorithm needs as the input grows
Best, average and worst case
running time on the most favorable, typical and least favorable inputs
Quicksort: O(n log n) on average, O(n²) in the worst case.
Dropping constants
Big-O ignores constant factors and lower-order terms
O(3n² + 5n) is written O(n²).
Array
elements stored next to each other in memory and accessed by index; access O(1), insert or delete in the middle O(n)
Dynamic array
an array that resizes itself, usually doubling its capacity when full
Python list, Java ArrayList, C++ vector.
Linked list
a chain of nodes where each node points to the next; insert or delete at a known node O(1), access by index O(n)
Doubly linked list
a linked list where each node points to both the next and the previous node
Stack
LIFO, last in first out: push and pop at the top in O(1)
Undo history; the function call stack.
Queue
FIFO, first in first out: add at the back, remove from the front in O(1)
Print jobs; breadth-first search.
Deque
double-ended queue: add or remove at both ends in O(1)
Hash table
maps keys to values using a hash function; lookup, insert and delete are O(1) on average
Python dict, JavaScript Map.
Hash function
turns a key into an index in the table; a good one spreads keys evenly
Hash collision
two keys map to the same index; handled by chaining or open addressing
Load factor
number of entries divided by number of buckets; when it gets too high, the table is resized
Set
a collection of unique elements, often built on a hash table
Checking whether an item is present in O(1) on average.
Tree
a hierarchy of nodes with a single root and no cycles
Binary tree
a tree where each node has at most two children
Binary search tree (BST)
a binary tree where every left subtree is smaller than the node and every right subtree is larger; search O(log n) if balanced, O(n) in the worst case
Balanced tree
a tree kept at height O(log n) so operations stay fast
AVL trees, red-black trees.
AVL tree
a self-balancing BST where the heights of the two subtrees of any node differ by at most 1
Red-black tree
a self-balancing BST that uses node colors to stay balanced; used in many standard library maps
Java TreeMap, C++ std::map.
Heap
a complete binary tree where each parent is smaller (min-heap) or larger (max-heap) than its children; insert and remove-top O(log n), peek O(1)
Priority queue
a queue that always removes the highest-priority element; usually implemented with a heap
Dijkstra's algorithm; task schedulers.
Trie
a tree for storing strings where each edge is a character; lookup takes O(length of the word)
Autocomplete.
B-tree
a balanced tree with many keys per node, designed to minimize disk reads
Database and file system indexes.
Graph
a set of vertices (nodes) connected by edges
Directed graph
a graph whose edges have a direction, from one vertex to another
Weighted graph
a graph where each edge has a cost or distance
Adjacency list
a graph stored as a list of neighbors for each vertex; space O(V + E), best for sparse graphs
Adjacency matrix
a graph stored as a V × V grid; space O(V²), checks an edge in O(1), best for dense graphs
DAG
directed acyclic graph: directed edges and no cycles
Task dependencies; build systems.
Union-find (disjoint set)
tracks elements split into groups; union and find run in nearly constant time with path compression
Kruskal's algorithm.
Bloom filter
a memory-efficient probabilistic set that answers "definitely not present" or "possibly present"
LRU cache
a cache that evicts the least recently used item; a hash table plus a doubly linked list gives O(1) get and put
Linear search
checks each element in turn; O(n)
Binary search
repeatedly halves a sorted array to find a value; O(log n); the input must be sorted
Bubble sort
repeatedly swaps neighboring elements that are out of order; O(n²)
Selection sort
repeatedly picks the smallest remaining element and moves it into place; O(n²)
Insertion sort
inserts each element into the sorted part of the array; O(n²) worst case, O(n) on nearly sorted data