Data Structures Cheat Sheet
Data Structures Cheat Sheet
Search
remove remove
add to insert at Random In-order for
from from Notes
end middle Access Access specific
end middle
element
Most efficient
use of
memory; use in
Array O(n) O(n) O(n) O(n) O(1) O(1) O(n) cases where
data size is
fixed.
best
case Implementation
is optimized for
O(1); speed. In many
List<T> O(1) O(n) O(n) O(1) O(1) O(n) cases, List will
worst be the best
case choice.
O(n)
best
case List is a better
O(1); choice, unless
Collection<T> O(1) O(n) O(n) O(1) O(1) O(n) publicly
worst exposed as
case 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 Shouldn't be
selected for
O(1); performance
Stack<T> O(1) N/A N/A N/A N/A N/A reasons, but
worst algorithmic
case ones.
O(n)
best
case Shouldn't be
selected for
O(1); performance
Queue<T> O(1) N/A N/A N/A N/A N/A reasons, but
worst algorithmic
case ones.
O(n)
Although in-
best best order access
time is
case case constant time,
O(1); O(1); it is usually
Dictionary<K,T> O(1) O(1) O(1)* O(1)* O(1) slower than
worst worst other
case case structures due
to the over-
O(n) O(n) head of looking
up the key.
https://www.clear.rice.edu/comp160/data_cheat.html 1/1