Quick Summary Data Structures Flashcards
Array
Strengths:
-Fast lookups
-Fast appends
Weaknesses:
-Fixed size (unless dynamic)
-Costly inserts and deletes
Worst Case
Space: O(n)
Lookup: O(1)
Append: O(1)
Insert: O(n)
Delete: O(n)
Hash Table
Strengths:
-Fast lookups
-Flexible keys (most data types can be used)
Weaknesses:
-Slow worst-case lookup
-Unordered
-Single-directional lookups (looking up key given value is O(n))
-Not cache friendly (often use linked lists, which don’t put data next to each other in memory)
Average Case
Space: O(n)
Lookup: O(1)
Insert: O(1)
Delete: O(1)
Worst Case
Space: O(n)
Lookup: O(n)
Insert: O(n)
Delete: O(n)
Linked List
Strengths:
-Fast operations on the ends
-Flexible size
Weaknesses:
-Costly lookups
Worst Case
Space: O(n)
Prepend: O(1)
Append: O(1)
Lookup: O(n)
Insert: O(n)
Delete: O(n)
Queue
Strengths:
-Fast operations
Uses:
-Breadth-first search
-Printers
-Web servers
-Processes (CPU scheduler)
Worst Case
Space: O(n)
Enqueue: O(1)
Dequeue: O(1)
peek: O(1)
Stack
Strengths:
-Fast Operations
Uses:
-Call stack
-Depth-first search
-String parsing
Can make with linked list or array- push/pop or insert/remove head
Worst Case
Space: O()
Push: O(1)
Pop: O(1)
peek: O(1)
Binary Tree