Algorithms and Data Structure Ch 3
Which of the following statements are true? 1. if obj1.equals(obj2) then obj1.hashcode() == obj2.hashcode() 2. if !obj1.equals(obj2) then obj1.hashcode() != obj2.hashcode()
1
Which of the following statements are true? 1. A hash map can store null as a value 2. A hash map can use null as a key 3. A hash map can't store null as a value 4. A hash map can't use null as a key
1 and 2
Which of the following statements are true? 1. A hash map can store duplicated values 2. A hash map can use duplicated keys 3. A hash map can't store duplicated values 4. A hash map can't use duplicated keys
1 and 4
What is the output of a BFS traversal in a normal binary search tree if the key insert order is 1,2,3,4,5,6,7?
1,2,3,4,5,6,7
If a balanced binary search tree contains 10 elements, then what is its depth?
3
Which of the following statements are true? 1. A hash table can store null as a value 2. A hash table can use null as a key 3. A hash table can't store null as a value 4. A hash table can't use null as a key
3 and 4
How many elements can be stored in a hash table T with a load factor of 40 and 10 slots?
400
Consider a hash table of size 500, and the hash function is i^3 mod 500. Which location is the key 1234 mapped to?
404
The sequence 10, 5, 9, 8, 4, 1, 23 has been put in a binary search tree. What is the LCA (Least Common Ancestor) of 9 and 4?
5
Given a hash table T with load factor 40 storing 2000 elements, what is the number of slots?
50
Suppose that you insert 100 keys in ascending order into a red-black BST. What is the height of the resulting tree?
7
What is the maximum depth of a binary search tree containing 10 elements?
9
What is the effect when a binary search tree becomes unbalanced?
A binary search tree that is not balanced degenerates into a linked list with O(n) linear performance
What is a data dictionary?
A data structure with insert, search, and optionally delete options
What does a hash function do?
A hash function computes an array index from the given key
Which of the following is true about a hash table?
A hash table has Big-O O(1) constant insert and search operation performance
What is a hash table?
A key-value data structure
Which of the following collections stores its elements in the insertion order?
A linked list
What is a hash function?
A method used to compute the hash number used for storing data in a hash table
What is the difference between an AVL and a red-black tree?
AVL trees provide faster lookups, and red-black trees provide faster insertion and removal
Which of the following statements is true about a binary tree?
All nodes are connected
A red-black tree is a binary search tree that has which of the following red-black properties?
All of the options - If a node is red, then both its children are black - Every simple path from a node to a descendant leaf contains the same number of black nodes - Every node is either red or black and every leaf is black
Which of the following strategies can you apply in case of a hash collision?
All of the options - Linear probing - Chaining - Double hashing
Which one of the following statements is not true about red-black trees?
An AVL tree is better than a red-black tree with the same data for searching, inserting, and deleting operations
What is a hash table?
An implementation of a data dictionary
When a data set is small and a hash table not used, what is the better data structure to use?
Array
Where do all operations start in a binary search tree?
At the root node
What is a data structure that supports range queries called?
Binary tree
In a red-black tree, what is the color of the root node?
Black
What color are the leaf nodes in a red-black tree?
Black
What is the number of black nodes from the root to a node called?
Black depth
What is the uniform number of black nodes in all paths from the root to the leaf nodes called?
Black height
How is a binary search tree balanced?
By using rotations to rearrange nodes to maintain the tree
How is hash table different from other data structures?
Data is stored as a value associated with a key
What operation does a binary search tree have for the elements in the tree that the linked list does not?
Finding the minimum and maximum elements
Where do we store items in open addressing hashing?
In the hash table itself
What is the universal hash function?
It chooses a hash function at random from a universal set of hash functions
What is the problem of using chaining in a hash table?
It degrades the performance of retrieving or searching for an element
How is a hash collision resolved?
It depends upon the hash function used
Which of the following is true about a hash function?
It has collisions where multiple keys map to the same space
Which of the following is an advantage of a binary search tree?
It has the worst case performance of O(log n)
What is a binary search tree?
It is a data structure that stores items, in which every node can have two children. It allows fast lookup addition and removal of items
What is linear probing?
It is a form of open addressing. When the hash function causes a collision, the probing searches for the closest following free location and inserts the new key there.
What is clustering in a hash table?
It is a problem with using linear probing in open addressing
What is a red black tree?
It is a self-balancing binary search tree with an additional space in each node for the node color
What is an in-order traversal of binary search trees?
It is a way of traversing each element of the tree in the following order: left -> root -> right, starting from the root node
What is a preorder traversal of a binary search tree?
It is a way of traversing each element of the tree in the following order: root -> left -> right, starting from the root node
What is hash chaining?
It is adding a data element to a linked list at the place in the array where a hash collision occurs
What is a node?
It is an element in a binary search tree
What is the remainder method of hashing?
It is constructing a hash function that uses the remainder based upon the table size
What is the advantage of linear probing over chaining?
It is typically faster than chaining in case of data insertion.
What is double hashing?
It is using a secondary hash function for the probing scheme used in open addressing
What is quadratic probing?
It uses the formula of h+(ai+bi2), where h is the initial hash value, and a and b are constants
What is a balanced binary search tree?
It's a binary search tree with the lowest possible number of levels
What are the main characteristics of a good hash function?
It's a function that returns a positive integer value. If objects are equal, then its hash numbers must also be the same
What is an AVL tree?
It's a self-balancing binary search tree, in which the difference between the heights of the left and right subtrees cannot be more than one for all nodes
Which of the following statements is true about chaining?
It's a solution for a hash collision problem. When two elements have the same hash, they are stored in the same bucket, which is often a linked list.
What does it mean that a tree is self-balancing?
It's a tree that automatically keeps its height small in the face of arbitrary item insertions and deletions
What is a hash collision?
It's when an object that we want to store in the data structure produces a hash assigning it to an already occupied slot.
What data structure is used with chaining?
Linked list
What is the advantage of chaining in a hash table?
No load limit
The in-order traversal sequence of a binary search tree is 25, 10, 14, 34, 9. Which one of the following is the post-order traversal sequence of the same tree?
None of the above - 30, 20, 10, 15, 25, 23, 39, 35, 42 - 15, 10, 25, 23, 20, 42, 35, 39, 30 - 10, 20, 15, 23, 25, 35, 42, 39, 30
Which of the following statements is false about a binary search tree?
None of the options - The left child is always smaller than its parent - The right child is always bigger than its parent - The left and right subtrees are also binary search trees
What is the best case scenario complexity of search in a binary search tree?
O(log n)
What time does a red-black tree guarantee for searching?
O(log n)
What is the complexity of a tree traversal operation?
O(n)
Linear probing, quadratic probing, and double hashing are examples of what?
Open addressing
What would happen if you do not override the hashcode() method?
The default hashcode() method would be used. Objects of such class would be inefficient as key values for the hash table or hash map data structure.
Which of the following is true about an ideal hash function?
The ideal hash function has few collisions
What is a leaf node?
The last node in a binary search tree that doesn't have any child
What will happen if you try to add duplicate key values in a hash map?
The new value will override the old one
What does a binary search tree have in common with a linked list?
The node has pointers to other nodes
If two objects have different hashes, then which of the following statement is true?
They are not equal
What happens when two objects with the same hashcode are added to a hash table?
They are stored in the same bucket/chain
If two objects have the same hash, then which of the following statement is true?
They might be equal
Why is a binary search tree kept balanced?
To keep the height of binary search tree minimal
How is data, or a value, retrieved from a data dictionary?
Using a key to find the associated value in a key-pair
How is data stored in a data dictionary?
Using a key-value pair
What is a disadvantage of arrays compared to a hash table?
Using the key as the index into the array is difficult and impractical
When is a binary search tree more performant or faster?
When the height is smaller
If a binary search tree contains 10 elements, then what is its depth?
up to 9
Which interface does jav
util.Hashtable implement? a. Map