DEV Community

Cover image for Big-O Cheatsheet to most common Data Structures and Sorting algorithms
Rohith V
Rohith V

Posted on

1 1

Big-O Cheatsheet to most common Data Structures and Sorting algorithms

Common data structure operations (Worst Case)

Access Search Insertion Deletion
Array O(1) O(n) O(n) O(n)
Stack O(n) O(n) O(1) O(1)
Queue O(n) O(n) O(1) O(1)
Singly Linkedlist O(n) O(n) O(1) O(1)
Doubly Linkedlist O(n) O(n) O(1) O(1)
Hash Table N/A O(n) O(n) O(n)
Binary Search Tree O(n) O(n) O(n) O(n)

Sorting Algorithms

Best Case Avergae Case Worst Case Space Complexity
Quicksort nlogn nlogn n^2 logn
Mergesort nlogn nlogn nlogn n
Heapsort nlogn nlogn nlogn O(1)
Bubble sort n n^2 n^2 O(1)
Insertion sort n n^2 n^2 O(1)
Selection sort n^2 n^2 n^2 O(1)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more