Algorithms and Data Structures Cheatsheet - Algorithms Part
Algorithms and Data Structures Cheatsheet - Algorithms Part
We summarize the performance characteristics of classic algorithms and data structures for sorting, priority queues, symbol
tables, and graph processing. We also summarize some of the mathematics useful in the analysis of algorithms, including
commonly encountered functions; useful formulas and approximations; properties of logarithms; asymptotic notations; and
solutions to divide-and- conquer recurrences.
Sorting.
The table below summarizes the number of compares for a variety of sorting algorithms, as implemented in this textbook. It
includes leading constants but ignores lower-order terms.
https://algs4.cs.princeton.edu/cheatsheet/ Page 2 of 10
Algorithms and Data Structures Cheatsheet 11/5/20, 9:06 PM
Priority queues.
The table below summarizes the order of growth of the running time of operations for a variety of priority queues, as
implemented in this textbook. It ignores leading constants and lower-order terms. Except as noted, all running times are
worst-case running times.
† amortized guarantee
https://algs4.cs.princeton.edu/cheatsheet/ Page 3 of 10
Algorithms and Data Structures Cheatsheet 11/5/20, 9:06 PM
Symbol tables.
The table below summarizes the order of growth of the running time of operations for a variety of symbol tables, as
implemented in this textbook. It ignores leading constants and lower-order terms.
sequential
search
n n n n n n
(in an
unordered list)
binary search
(in a sorted log n n n log n n n
array)
binary search
tree n n n log n log n sqrt(n)
(unbalanced)
red-black
BST log n log n log n log n log n log n
(left-leaning)
AVL log n log n log n log n log n log n
hash table
(separate- n n n 1† 1† 1†
chaining)
hash table
(linear- n n n 1† 1† 1†
probing)
† uniform
hashing assumption
Graph processing.
The table below summarizes the order of growth of the worst-case running time and memory usage (beyond the memory for
the graph itself) for a variety of graph-processing problems, as implemented in this textbook. It ignores leading constants
and lower-order terms. All running times are worst-case running times.
https://algs4.cs.princeton.edu/cheatsheet/ Page 4 of 10
Algorithms and Data Structures Cheatsheet 11/5/20, 9:06 PM
https://algs4.cs.princeton.edu/cheatsheet/ Page 5 of 10
Algorithms and Data Structures Cheatsheet 11/5/20, 9:06 PM
Copyright © 2000–2019 Robert Sedgewick and Kevin Wayne. All rights reserved.
https://algs4.cs.princeton.edu/cheatsheet/ Page 10 of 10