Data Structures and Abstract Data Types Flashcards
What is the time complexity for hash table lookup?
O(1)
Name 2 collision resolution methods
Separate chaining (closed addressing), linear probing (open addressing)
What is the time complexity for linked list insertion and deletion? (Assuming the index for insertion/deletion is already known)
O(1)
What is the time complexity for linked list search?
O(n)
State three features of a good hashing algorithm
- The hash function uses all the input data
- The hash function uniformly distributes the data across the entire set of possible hash values
- The hash function generates very different hash values for similar (but non-identical) strings
Name 2 Abstract Data Types.
Stack and Queue
How does a stack work?
Elements are pushed onto the stack, or popped from the stack.
The first element pushed onto the stack is the last element popped from the stack (FILO)
How does a queue work?
Elements are enqueued into the queue, or dequeued from the queue.
The first element enqueued is also the first element dequeued (FIFO)
What methods are required for a Queue ADT?
Enqueue: add an element to the queue
Dequeue: get the next element from the queue
What methods are required for a Stack ADT?
Push: add an element to the stack
Pop: get the next element from the stack
What are the key features of a Circular Queue?
Circular queues have a fixed capacity.
The last location in the array wraps around to the first location.
What does a hash function do in a hash table?
Hash function takes an input key and returns a location/index of fixed size. Each unique key hashes to the same location/index.