HashTableSet Flashcards
Map ADT
has functions: size(), get(k), put(k,v), remove(k), find(k)
Hash Table (unordered_Map)
Size of HT is proportional to the number of keys (not the value of keys). Key is the input/parameter used by a hash function that will generate a hash code (output) that will assign the element into an index and store its key into the data field.
Hash Function
Will take in a keyvalue and output the hashcode to generate the index value for insertion into a table/map. Must be fast.
Hash Table Concerns
Hashcodes are not unique, multiple Hash Keys will generate the same Hash Code and result in collisions. Collisions are the main focus of (maintaining) optimal
runtime of the Hash Table data structure.
What is a possible ADT using Red-Black Tree DS?
Red-Black Tree can support a (C+++) Set ADT
What is a possible ADT using Linked List DS?
Linked List can support a (C++) List ADT
What is a possible ADT using ArrayList DS?
ArrayList can support a (C++) Vector ADT
Set ADT
has functions: size(), insert(x) [no duplicates], remove(x), find(x)
Lexicon vs. Numbers
Strings as a sequence, numbers are single entity
Red-Black Tree Advantages
Faster Insert than AVL: RBT insertion traverses the tree once instead of twice.
While longer than AVL, finding is still guaranteed O(log n )
Red-Black Tree Advantages
Slower to Find (than AVL): RBT are (slightly) taller than AVL trees
Red-Black Tree Insert Algorithm
While not leaf: 1. Move down tree to destination, if node has two red children recolor and rotate as necessary to fix. 2. Insert node 3. Do final rotations to fix tree. (not need to go back up tree.
Runtime: O(log n)
Can any node have 2 red children?
Black nodes can have 2 red children. inserting a new (red) node into this set will violate RBT rule and thus recoloring (red becomes black and black becomes red) and rotation will be in place but this ensures when inserting into this scenario, the result will be okay.
Red node can never have red children.
What DS can implement the Set ADT?
Array List, Linked List, Binary Search Tree, Randomized Search Tree, AVL Tree, Red-Black Tree
What DS can implement the Map ADT?
Array List, Linked List, Binary Search Tree, Randomized Search Tree, AVL Tree, Red-Black Tree
True or False: Set ADT can be modified to relatively simply implement Map ADT
True
True or False: Map ADT can be modified to relatively simply implement Set ADT
True
True or False: Implementing Set ADT using RBT has better worst case Big-O runtime complexity for finding and inserting elements than implementing the Set ADT using Linked List
True
Worst Case Time Complexity of Insert to Hash Table
O(n)
Averge Case Time Complexity of Insert to Hash Table
O(1)