0% found this document useful (0 votes)
38 views

Cheat Sheet

Skdn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Cheat Sheet

Skdn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Data Structure Operations Cheat Sheet

Space
Average Case Time Complexity Worst Case Time Complexity
Data Complexity
Suucture
Accessing Accessingg Insertion Deletion Worst Case
Name Search Insertion Deletion Search
element nclement
O(n) On)
ATays On) O(n) O1) O(n) O(n)
O1) On)
On)
Stack O(1) O(n) O(n) O1) O1)
On) O(n) O(1)
O(1) O(1) O(n)
Queues Om) Om) O(1) O(1) Ofn) O(n)
Binay O(n) O(n)
O(n) O(n) On) O(n) On) O(n) On)
Trees

Binary O(n) O(n)


Ollogn) On) On) On)
Search Ologn) Ologn) Ollogn)
Trees
Balanced
Binary Ologn) Ollogn) Ologn) Ollogn)
Ologn) Ollogn) O(logn) Ologn) Ollogn)
Search
Trees
Hash On) On) On) O(n)
N/A O(1) O(1) O(1) N/A
Tables
Note: For best case operations, the time complexities are O().

Soring Algorithms Cheat Shcet


Space

Sorting Time Complexity Is Sorting Class


Complexity Remarks
Algorithn Best Average Worst Stable? Type
Worst Case
Name
Case Case Case
Yes Comparison Not a prelerred sorting algorithm.
Bubble Sor O(n) D(n) On) O()

In the best case (already sorted), every


O(n2) O(n) O(1) Yes Comparison insert requires constant ume
Insertion Sort O(n)

Even a perfecly sorted aray requires


O(n) On) Otn) O(1) Yes Comparison scanung the entire aray
Selection Sort

On arrays, il requires O(n) space; and


on linked lists, it requires conslant
O(nlogn) On) Yes Comparison
Merge Sort Onlogn) O(nlogn)
space

By usung nput array as storage lor the


heap, it is 1possible to achieve constant
Onlogn) O(nlogn) O(1) No Comparison
Heap Sort O(nlogn) Space

Randomly pickng a pivot value can


help avoid worst case scenarios such as
Omlogn) On2) Ologn) No Comparison
Quick Sor O(nlogn) a perlectly sorted array.

Perforning inorder lraversal on the


O(n) O(n) Yes Compaison balanced binary search trec.
Tree Sort Onlogn)Ofnlogn)
Where k is the range of the non-
O(n + k) O(n +k) Yes Linear
Counting Sort O(n + k) negative key values.

Bucket sot is stable, il the underlying


O(n - O(n + k) O(n2) Om) Yes Tnear Sorting algornthm is stable.
Bucket Sort

Radix sort is stable, il the underlying


O(dn) O(dn) Od +n) Yes Lanear sorting algorithm is stable.
Radix Sort Oldn)

You might also like