Data Structures Flashcards
Array Index
O(1)
Array Search
O(n)
Hash Table Search
O(1) avg, O(n) worst
Hash Table Insertion/Deletion
O(1) avg, O(n) worst
Arrays are optimal for?
Indexing. Slow to search, insert, and delete.
Linked lists, stacks, and queues are optimal for?
Insertion and deletion. Slow at indexing and searching.
Linked list, Stack, Queue Insertion/Deletion
O(1)
Linked List, Stack, Queue Index/Search
O(n)
HashMaps are optimal for?
Searching, insertion, and deletion
Hash Collision
When a hash function returns the same output for two different inputs
Binary Search Tree
Access, search, insertion, and deletion are all log n (light green)
Heap
A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally, Heaps can be of two types:
Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.
Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.