Sie sind auf Seite 1von 8

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

Big-O Cheat Sheet Searching Sorting Data Structures Heaps Graphs Chart Comments

Sikkim Manipal University


Smude.edu.in/Admissions_Open

Distance Education Programs from Students' Most Preferred University


2,616
Tweet

1.6k

I receive

$8.00 / wk
on Gittip.

Know Thy Complexities!


Hi there! This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science. When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting together the best, average, and worst case complexities for search and sorting algorithms so that I wouldn't be stumped when asked about them. Over the last few years, I've interviewed at several Silicon Valley startups, and also some bigger companies, like Yahoo, eBay, LinkedIn, and Google, and each time that I prepared for an interview, I thought to myself "Why oh why hasn't someone created a nice Big-O cheat sheet?". So, to save all of you fine folks a ton of time, I went ahead and created one. Enjoy!
Good Fair Poor

Searching
Algorithm Data Structure Time Complexity Average Graph of |V| vertices and |E| edges Graph of |V| vertices Breadth First Search (BFS) and |E| edges Sorted array of n Binary search elements Linear (Brute Force) Array Shortest path by Dijkstra, Graph with |V| vertices using a Min-heap as priority and |E| edges queue Depth First Search (DFS)
O(log(n)) O(n) O((|V| + |E|) log |V|)

Worst
O(|E| + |V|) O(|E| + |V|) O(log(n)) O(n) O((|V| + |E|) log |V|)

Space Complexity Worst


O(|V|) O(|V|) O(1) O(1) O(|V|)

1 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

Algorithm Shortest path by Dijkstra, using an unsorted array as priority queue Shortest path by Bellman-Ford

Data Structure

Time Complexity Average Worst


O(|V|^2)

Space Complexity Worst


O(|V|)

Graph with |V| vertices O(|V|^2) and |E| edges Graph with |V| vertices O(|V||E|) and |E| edges

O(|V||E|)

O(|V|)

Sorting
Algorithm Data Structure Best Quicksort Mergesort Heapsort Bubble Sort Insertion Sort Select Sort Bucket Sort Radix Sort Array Array Array Array Array Array Array Array
O(n log(n)) O(n log(n)) O(n log(n)) O(n) O(n) O(n^2) O(n+k) O(nk)

Time Complexity Average


O(n log(n)) O(n log(n)) O(n log(n)) O(n^2) O(n^2) O(n^2) O(n+k) O(nk)

Worst
O(n^2) O(n log(n)) O(n log(n)) O(n^2) O(n^2) O(n^2) O(n^2) O(nk)

Worst Case Auxiliary Space Complexity Worst


O(n) O(n) O(1) O(1) O(1) O(1) O(nk) O(n+k)

Data Structures
Data Structure Indexing Basic Array Dynamic Array SinglyLinked List DoublyLinked List Skip List Hash Table
O(1) O(1)

Time Complexity Average Search Insertion


O(n) O(n) O(n)

Deletion
O(n)

Indexing
O(1) O(1)

Worst Search Insertion


O(n) O(n) O(n)

Space Complexity Worst Deletion


O(n) O(n) O(n)

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(1)

O(1)

O(n) O(n log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(1) O(1) O(1) -

O(n) O(n)

O(n) O(n)

O(n) O(n)

2 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

Data Structure Indexing Binary Search O(log(n)) Tree Cartresian Tree B-Tree O(log(n)) Red-Black O(log(n)) Tree Splay Tree AVL Tree O(log(n)) Average Search Insertion

Time Complexity Deletion Indexing Worst Search Insertion


O(n) O(n)

Space Complexity Worst Deletion


O(n) O(n)

O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) -

O(n)

O(n)

O(n)

O(n)

O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

Heaps
Heaps Heapify Find Max Linked List (sorted) Linked List (unsorted) Binary Heap Binomial Heap Fibonacci Heap
O(n) O(1) O(n) O(1)

Time Complexity Extract Increase Insert Max Key


O(1) O(n) O(log(n)) O(n) O(1) O(log(n)) O(log(n)) O(n) O(1)

Delete
O(1) O(1)

Merge
O(m+n) O(1)

O(log(n)) O(log(n)) O(m+n) O(log(n)) O(log(n)) O(log(n)) O(1) O(log(n))* O(1)

O(log(n)) O(log(n)) O(1)

O(log(n))* O(1)*

Graphs
Node / Edge Management Adjacency list Incidence list Adjacency matrix Incidence matrix Storage
O(|V|+|E|) O(|V|+|E|) O(|V|^2) O(|V| |E|)

Add Vertex
O(1) O(1) O(|V|^2) O(|V| |E|)

Add Edge
O(1) O(1) O(1) O(|V| |E|)

Remove Vertex
O(|E|) O(|V|^2) O(|V| |E|)

Remove Edge
O(|E|) O(1) O(|V| |E|)

Query
O(|V|) O(|E|) O(1) O(|E|)

O(|V| + |E|) O(|E|)

Notation for asymptotic growth


letter (theta) (big-oh) O (small-oh) o bound upper and lower, tight upper, not tight
[1]

growth equal
[2]

upper, tightness unknown less than or equal[3] less than

3 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

(big omega) lower, tightness unknown greater than or equal (small omega) lower, not tight greater than [1] Big O is the upper bound, while Omega is the lower bound. Theta requires both Big O and Omega, so that's why it's referred to as a tight bound (it must be both the upper and lower bound). For example, an algorithm taking Omega(n log n) takes at least n log n time but has no upper limit. An algorithm taking Theta(n log n) is far preferential since it takes AT LEAST n log n (Omega n log n) and NO MORE THAN n log n (Big O n log n).SO [2] f(x)=(g(n)) means f (the running time of the algorithm) grows exactly like g when n (input size) gets larger. In other words, the growth rate of f(x) is asymptotically proportional to g(n). [3] Same thing. Here the growth rate is no faster than g(n). big-oh is the most useful because represents the worst-case behavior. In short, if algorithm is __ then its performance is __ algorithm performance o(n) <n O(n) n (n) =n (n) n (n) >n

Symbolic Regression
www.dtreg.com/gep.htm

Gene Expression Programming for math and logic functions

Big-O Complexity Chart


This interactive chart, created by our friends over at MeteorCharts, shows the number of operations (y axis) required to obtain a result as the number of elements (x axis) increase. O(n!) is the worst complexity which requires 720 operations for just 6 elements, while O(1) is the best complexity, which only requires 1 operation for any number of elements.

4 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

Contributors
Edit these tables! 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Eric Rowell Quentin Pleple Nick Dizazzo Michael Abed Adam Forsyth Jay Engineer Josh Davis makosblade Alejandro Ramirez Joel Friedly Robert Burke David Dorfman Eric Lefevre-Ardant Thomas Dybdahl Ahle

5 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

What the Bible Says About Money (Shocking) How to Make Rich Article Pins [Cheat Sheet] How to Upgrade a PS4 Hard Drive Gallery: 20 Terrifying Trails Around The World

3 Signs You're Dangerously Close to a Heart Attack Matt Damon Won't Be Robin to Ben Affleck's Batman Tom Cruise's Reign Is Over: Katie Holmes Joins Twitter! | DAILY Surprising Way Cruise Ships Fill Their Unsold Cabins

145 comments

57

Best

Community

Share

Michael Mitchell

This is great. Maybe you could include some resources (links to khan academy, mooc etc) that would explain each of these concepts for people trying to learn them.
114

Amanda Harlin

Yes! Please & thank you


33 Cam Tyler 9

This explanation in 'plain English' helps: http://stackoverflow.com/quest...

Arjan Nieuwenhuizen

Here are the links that I know of. #1) http://aduni.org/courses/algor... #2) http://ocw.mit.edu/courses/ele... #3) https://www.udacity.com/course... probably as good or maybe better # 2, but I have not had a chance to look at it. http://ocw.mit.edu/courses/ele... Sincerely, Arjan p.s. https://www.coursera.org/cours... This course has just begun on coursera (dated 1 July 2013), and looks very
6 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

7 of 8

18/11/2013 11:46 AM

Big-O Algorithm Complexity Cheat Sheet

http://bigocheatsheet.com/

Cv Resume Format
www.Quikr.com

Multiple Positions Open In Your Desired Field. Apply Now. Free!


Page styling via Bootstrap Comments via Disqus Algorithm detail via Wikipedia Big-O complexity chart via MeteorCharts Table source hosted on Github Mashup via @ericdrowell

8 of 8

18/11/2013 11:46 AM

Das könnte Ihnen auch gefallen