Docsity

Big-O Cheat Sheet Sorting, Searching and Data Structures Algorithms, Cheat Sheet of Data Structures and Algorithms

Toggle sidebar
bg1
Big-O Cheat Sheet
Generated December 2013.
B. Amos
1 Searching
Algorithm Data Structure Time Complexity Space Complexity
Average Worst
Depth First Search (DFS) Graph of |V|vertices and
|E|edges
-O(|E|+|V|)O(|V|)
Breadth First Search
(BFS) Graph of |V|vertices and
|E|edges
-O(|E|+|V|)O(|V|)
Binary search Sorted array of n elements O(log(n)) O(log(n)) O(1)
Linear (Brute Force) Array O(n)O(n)O(1)
Shortest path by Dijkstra,
using a Min-heap as prior-
ity queue
Graph with |V|vertices
and |E|edges
O((|V|+|E|) log |V|)O((|V|+|E|) log |V|)O(|V|)
Shortest path by Dijkstra,
using an unsorted array as
priority queue
Graph with |V|vertices
and |E|edges
O๎˜€|V|2๎˜O๎˜€|V|2๎˜O(|V|)
Shortest path by Bellman-
Ford Graph with |V|vertices
and |E|edges
O(|V||E|)O(|V||E|)O(|V|)
1
pf2