100% found this document useful (1 vote)
438 views

Data Structures Cheat Sheet

This document provides a cheat sheet for common data structures, including their time complexities for common operations like add, remove, search, and access. It lists the time complexities of adding, removing from ends and middles, random access, and searching for specific elements in arrays, lists, linked lists, stacks, queues, and dictionaries. For most structures, adding and removing take O(1) time on average but O(n) time worst case, while searching and random access are typically O(1) or O(n) depending on the structure.

Uploaded by

Philippe Jean
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
438 views

Data Structures Cheat Sheet

This document provides a cheat sheet for common data structures, including their time complexities for common operations like add, remove, search, and access. It lists the time complexities of adding, removing from ends and middles, random access, and searching for specific elements in arrays, lists, linked lists, stacks, queues, and dictionaries. For most structures, adding and removing take O(1) time on average but O(n) time worst case, while searching and random access are typically O(1) or O(n) depending on the structure.

Uploaded by

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

Data Structures Cheat Sheet

[Data Structures I] [Data Structures II] [Data Structures III] [Data Structures IV] [Data Structures Cheat Sheet]

Search for
remove from remove from Random
add to end insert at middle In-order Access specific Notes
end middle Access
element

Most efficient use of


memory; use in cases
Array O(n) O(n) O(n) O(n) O(1) O(1) O(n) where data size is
fixed.

best case O(1); Implementation is


optimized for speed.
List<T> worst case O(1) O(n) O(n) O(1) O(1) O(n) In many cases, List
O(n) will be the best choice.

best case O(1); List is a better choice,


Collection<T> worst case O(1) O(n) O(n) O(1) O(1) O(n) unless publicly
exposed as API.
O(n)

Many operations are


LinkedList<T> O(1) O(1) O(1) O(1) O(n) O(1) O(n) fast, but watch out for
cache coherency.

best case O(1); Shouldn't be selected


for performance
Stack<T> worst case O(1) N/A N/A N/A N/A N/A reasons, but
O(n) algorithmic ones.

best case O(1); Shouldn't be selected


for performance
Queue<T> worst case O(1) N/A N/A N/A N/A N/A reasons, but
O(n) algorithmic ones.

Although in-order
access time is
best case O(1); best case O(1); constant time, it is
Dictionary<K,T> worst case O(1) worst case O(1) O(1)* O(1)* O(1) usually slower than
other structures due to
O(n) O(n) the over-head of
looking up the key.

You might also like