0% found this document useful (0 votes)
7 views1 page

Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell

This document is a Big-O cheat sheet that summarizes the time and space complexities of common algorithms and data structures, aimed at helping individuals prepare for technical interviews. It includes a variety of algorithms for sorting and data structure operations, detailing their average, worst, and best case complexities. The creator, Eric, designed this resource to save time for those studying for interviews at major tech companies.

Uploaded by

Anchal Mathur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell

This document is a Big-O cheat sheet that summarizes the time and space complexities of common algorithms and data structures, aimed at helping individuals prepare for technical interviews. It includes a variety of algorithms for sorting and data structure operations, detailing their average, worst, and best case complexities. The creator, Eric, designed this resource to save time for those studying for interviews at major tech companies.

Uploaded by

Anchal Mathur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Big-O Cheat Sheet Download PDF

NSIMD is a vectorization library that abstracts OPEN


SIMD programming.

37.5k Tweet Share Share Share


Shares

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 Google, Facebook,
Yahoo, LinkedIn, and Uber, and each time that I prepared for an interview, I thought to myself "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! - Eric

Check out El Grapho, a graph data visualization library that supports millions of nodes
and edges

Big-O Complexity Chart


Horrible Bad Fair Good Excellent

O(n!) O(2^n)
O(n^2)

O(n log n)
Operations

O(n)

O(log n), O(1)

Elements

NSIMD is a vectorization library that abstracts OPEN


SIMD programming.

Common Data Structure Operations


Data Structure Time Complexity Space Complexity
Average Worst Worst
Access Search Insertion Deletion Access Search Insertion Deletion
Array Θ(1) Θ(n) Θ(n) Θ(n) O(1) O(n) O(n) O(n) O(n)

Stack Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)

Queue Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)

Singly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)

Doubly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)

Skip List Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n log(n))

Hash Table N/A Θ(1) Θ(1) Θ(1) N/A O(n) O(n) O(n) O(n)

Binary Search Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)

Cartesian Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(n) O(n) O(n) O(n)

B-Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

Red-Black Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

Splay Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(log(n)) O(log(n)) O(log(n)) O(n)

AVL Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

KD Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)

Array Sorting Algorithms


Algorithm Time Complexity Space Complexity
Best Average Worst Worst
Quicksort Ω(n log(n)) Θ(n log(n)) O(n^2) O(log(n))

Mergesort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)

Timsort Ω(n) Θ(n log(n)) O(n log(n)) O(n)

Heapsort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(1)

Bubble Sort Ω(n) Θ(n^2) O(n^2) O(1)

Insertion Sort Ω(n) Θ(n^2) O(n^2) O(1)

Selection Sort Ω(n^2) Θ(n^2) O(n^2) O(1)

Tree Sort Ω(n log(n)) Θ(n log(n)) O(n^2) O(n)

Shell Sort Ω(n log(n)) Θ(n(log(n))^2) O(n(log(n))^2) O(1)

Bucket Sort Ω(n+k) Θ(n+k) O(n^2) O(n)

Radix Sort Ω(nk) Θ(nk) O(nk) O(n+k)

Counting Sort Ω(n+k) Θ(n+k) O(n+k) O(k)

Cubesort Ω(n) Θ(n log(n)) O(n log(n)) O(n)

Learn More
Cracking the Coding Interview: 150 Programming Questions and Solutions
Introduction to Algorithms, 3rd Edition
Data Structures and Algorithms in Java (2nd Edition)
High Performance JavaScript (Build Faster Web Application Interfaces)

Get the Official Big-O Cheat Sheet Poster

Contributors
Eric Rowell Quentin Pleple Michael Abed Nick Dizazzo Adam Forsyth Felix Zhu Jay Engineer Josh Davis
Nodir Turakulov Jennifer Hamon David Dorfman Bart Massey Ray Pereda Si Pham Mike Davis mcverry
Max Hoffmann Bahador Saket Damon Davison Alvin Wan Alan Briolat Drew Hannay Andrew Rasmussen
Dennis Tsang Vinnie Magro Adam Arold Alejandro Ramirez Aneel Nazareth Rahul Chowdhury Jonathan McElroy
steven41292 Brandon Amos Joel Friedly Casper Van Gheluwe Eric Lefevre-Ardant Oleg Renfred Harper
Piper Chester Miguel Amigot Apurva K Matthew Daronco Yun-Cheng Lin Clay Tyler Orhan Can Ozalp Ayman Singh
David Morton Aurelien Ooms Sebastian Paaske Torholm Koushik Krishnan Drew Bailey Robert Burke

Make this Page Better


Edit these tables!

Curbside Pick Up In 1-2 Hours


Petco

Sponsored

One Thing All Cheaters Have In Couple Who Waits 9 Years To How To Tell When a Slot Is Close
Common, Brace Yourself Open Their Wedding Present to Hitting a Jackpot
Peoplewhiz Gets A Rude Awakening Get it on Google Play | Billionaires Casino
MyDailyMagazine

Cheap Air Cooler Takes United This List Contains The Dog Signs of Hemophilia (Symptoms
States By Storm. The Idea Is Breeds You'll Want To Avoid At May Startle You)
Genius All Cost Hemophilia | Search Ads
AirCooler SoGoodly

492 Comments Big-O Cheat Sheet ! Disqus' Privacy Policy "


1 Login

, Recommend 318 t Tweet f Share Sort by Best

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Michael Mitchell
− ⚑
7 years ago

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.
368 △ ▽ 1 Reply
Amanda Harlin > Michael Mitchell
− ⚑
7 years ago

Yes! Please & thank you


80 △ ▽ Reply
Asim Ahmad > Amanda Harlin
− ⚑
2 years ago

Can you Explain the Above Algorithm.??


△ ▽ 7 Reply
Anonymous > Asim Ahmad
− ⚑
2 years ago

Mr.
you can learn these algorithms easily in google by searching
Don't always ask or wait for someone to post things for you go out and search on internet
You will find everything you want to learn

If you are a beginner in Data structures and algorithms then visit mycodeschool youtube channel and learn there
if you want more then email me at [email protected] I will help you as much as I can
26 △ ▽ 8 Reply
Careerdrill > Anonymous
− ⚑
a month ago

https://www.careerdrill.com/
△ ▽ Reply

Cam Cecil > Michael Mitchell


− ⚑
7 years ago

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


35 △ ▽ 1 Reply
Richard Wheatley > Cam Cecil
− ⚑
5 years ago

this is plain english.


14 △ ▽ 2 Reply

Arjan Nieuwenhuizen > Michael Mitchell


− ⚑
7 years ago edited

Here are the links that I know of.

#1) http://aduni.org/courses/al...
#2) http://ocw.mit.edu/courses/...
#3) https://www.udacity.com/cou...

probably as good or maybe better # 2, but I have not had a chance to look at it.
http://ocw.mit.edu/courses/...

Sincerely,
Arjan

p.s.
https://www.coursera.org/co...
This course has just begun on coursera (dated 1 July 2013), and looks very good.
21 △ ▽ Reply
fireheron > Arjan Nieuwenhuizen
− ⚑
7 years ago

Thank you Arjan. Espaecially the coursera.org one ;-)


5△ ▽ Reply
@hangtwentyy > fireheron
− ⚑
5 years ago

also this! http://opendatastructures.org


7△ ▽ Reply
yth > @hangtwentyy
− ⚑
5 years ago

thank you for sharing this.


1△ ▽ Reply

Eduardo Sánchez > Michael Mitchell


− ⚑
4 years ago

There is an amazing tutorial for Big O form Derek Banas in Youtube, that guy is amazing explaining!!! ▶ Big O Notations — disq.us
10 △ ▽ Reply
Sudhanshu Mishra > Eduardo Sánchez
− ⚑
4 years ago

Cool! This is a more than adequate introduction! Thanks a ton for sharing!
1△ ▽ Reply
Mohammed Hameed > Eduardo Sánchez
− ⚑
9 months ago

Thanks...
△ ▽ Reply
CodeMunkey > Michael Mitchell
− ⚑
4 years ago

Not sure if this helps, but here's a more visual learner for some of these algorithms - if you're interested. http://visualgo.net
3△ ▽ Reply
Divyendra Patil > Michael Mitchell
− ⚑
2 years ago

www.codenza.us
1△ ▽ Reply
Abby Jones > Michael Mitchell
− ⚑
7 months ago

Fabulous idea!
△ ▽ Reply
Jeshika Morneau > Michael Mitchell
− ⚑
a year ago

Or you could have supplied them in your comment instead.


△ ▽ Reply
nate lipp > Michael Mitchell
− ⚑
3 years ago

This is a well put together introduction


https://www.interviewcake.c...
△ ▽ Reply
Nhập Hàng Ngoại > Michael Mitchell
− ⚑
3 years ago

http://fashionfor.life/t-sh... ⛺ View — uploads.disquscdn.com


△ ▽ 9 Reply

Load more comments

✉ Subscribe d Add Disqus to your site ⚠ Do Not Sell My Data

Sponsored

Couple Who Waits 9 Years To One Thing All Cheaters Have Cheap Air Cooler Takes
Open Their Wedding Present In Common, Brace Yourself United States By Storm. The
Gets A Rude Awakening Peoplewhiz Idea Is Genius
MyDailyMagazine AirCooler

How To Tell When a Slot Is This List Contains The Dog Man Who Picked Apple in
Close to Hitting a Jackpot Breeds You'll Want To Avoid 2003 and Bitcoin in 2016
Get it on Google Play | Billionaires Casino At All Cost Says "Buy Genesis"
SoGoodly The Legacy Report

You might also like