What is the primary purpose of string hashing?
A) To sort strings
B) To convert strings into fixed-size integers
C) To compare strings directly
D) To store strings in a database
Answer: B) To convert strings into fixed-size integers
Which of the following is a common use of string hashing?
A) Data compression
B) Pattern matching
C) String sorting
D) File encryption
Answer: B) Pattern matching
What is a hash function?
A) A function that converts data into a binary format
B) A function that maps input data of arbitrary size to fixed-size values
C) A function that encrypts data
D) A function that sorts data
Answer: B) A function that maps input data of arbitrary size to fixed-size values
Which property is crucial for a good hash function?
A) It should be linear
B) It should minimize collisions
C) It should be easy to compute
D) Both B and C
Answer: D) Both B and C
What is a collision in the context of hashing?
A) When two strings hash to different values
B) When two different strings hash to the same value
C) When the hash function fails
D) When a string is empty
Answer: B) When two different strings hash to the same value
Which of the following is a common approach to handle collisions?
A) Deleting the entry
B) Open addressing
C) Ignoring the collision
D) Using a longer string
Answer: B) Open addressing
What is a rolling hash?
A) A hash function that rehashes the entire string for each new substring
B) A hash function that updates its value incrementally
C) A hash function that uses random values
D) A hash function used for encryption
Answer: B) A hash function that updates its value incrementally
In string hashing, what is the purpose of a modulus operation?
A) To increase the hash value
B) To reduce the hash value to fit within a certain range
C) To sort the string
D) To concatenate strings
Answer: B) To reduce the hash value to fit within a certain range
What is the time complexity of computing a hash for a string of length n using a simple polynomial hash function?
A) O(1)
B) O(n)
C) O(n log n)
D) O(n^2)
Answer: B) O(n)
What is one disadvantage of using a naive hash function?
A) It is too complex to implement
B) It may produce too many collisions
C) It is inefficient for short strings
D) It requires too much memory
Answer: B) It may produce too many collisions
Which of the following hash functions is commonly used for string hashing?
A) SHA-256
B) MD5
C) Rabin-Karp hash
D) All of the above
Answer: D) All of the above
In the context of string hashing, what does “perfect hashing” mean?
A) A hash function that uses no memory
B) A hash function that never produces collisions
C) A hash function that is always faster than others
D) A hash function that sorts strings
Answer: B) A hash function that never produces collisions
What is a common application of string hashing in databases?
A) Data retrieval
B) Data insertion
C) Data sorting
D) Data deletion
Answer: A) Data retrieval
What does the term “load factor” refer to in hashing?
A) The ratio of stored entries to the total number of slots in a hash table
B) The size of the input string
C) The number of collisions in a hash table
D) The efficiency of a hash function
Answer: A) The ratio of stored entries to the total number of slots in a hash table
Which of the following is NOT a characteristic of a good hash function?
A) Deterministic
B) Uniform distribution
C) Complex calculations
D) Fast computation
Answer: C) Complex calculations
How does a cryptographic hash function differ from a regular hash function?
A) It is slower to compute
B) It is not deterministic
C) It is easier to reverse
D) It is only used for strings
Answer: A) It is slower to compute
What is the result of applying a hash function to an empty string?
A) A random value
B) A predefined constant
C) Zero
D) A null value
Answer: B) A predefined constant
Which hashing technique would be most efficient for large datasets with frequent insertions and deletions?
A) Separate chaining
B) Open addressing
C) Double hashing
D) Perfect hashing
Answer: A) Separate chaining
What happens if two strings hash to the same value using a hash function?
A) The hash function is ineffective
B) A collision occurs
C) The strings are identical
D) The hash function is reset
Answer: B) A collision occurs
Which of the following is a simple example of a hash function?
A) Summing the ASCII values of characters
B) Reversing the string
C) Sorting the characters
D) Finding the length of the string
Answer: A) Summing the ASCII values of characters
In string hashing, what does a “hash table” refer to?
A) A data structure that stores hash values
B) A mapping of keys to values
C) A fixed-size array used for storing hashed strings
D) All of the above
Answer: D) All of the above
What is the primary benefit of using a hashing technique in programming?
A) It simplifies data storage
B) It improves data retrieval speed
C) It increases memory usage
D) It enhances data security
Answer: B) It improves data retrieval speed
What does it mean to “rehash” a hash table?
A) To apply a new hash function to existing entries
B) To increase the size of the hash table
C) To delete all entries
D) To compress the data
Answer: A) To apply a new hash function to existing entries
Which of the following is an example of a hash collision resolution technique?
A) Chaining
B) Appending
C) Overwriting
D) Sorting
Answer: A) Chaining
What is a disadvantage of separate chaining for collision resolution?
A) Increased memory usage
B) Slower performance
C) Higher load factor
D) Limited to fixed-size tables
Answer: A) Increased memory usage
How does a hash table maintain efficiency?
A) By using a larger size than needed
B) By keeping the load factor below a certain threshold
C) By allowing dynamic resizing
D) By using complex hash functions
Answer: B) By keeping the load factor below a certain threshold
What is the time complexity of searching for an element in a well-distributed hash table?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)
Which hash function is based on polynomial rolling?
A) MD5
B) Rabin-Karp
C) SHA-256
D) Linear probing
Answer: B) Rabin-Karp
What type of data structure is often used to implement separate chaining?
A) Array
B) Linked list
C) Stack
D) Queue
Answer: B) Linked list
What is a major disadvantage of open addressing?
A) It uses too much memory
B) It can lead to clustering
C) It is slower than separate chaining
D) It cannot handle collisions
Answer: B) It can lead to clustering
In which scenario would you prefer string hashing?
A) When exact string matching is required
B) When sorting strings
C) When counting distinct strings
D) When concatenating strings
Answer: A) When exact string matching is required
What is the significance of the hash value?
A) It uniquely identifies an entry in a hash table
B) It determines the string length
C) It specifies the original string
D) It serves as an encrypted value
Answer: A) It uniquely identifies an entry in a hash table
How does the choice of a hash function impact performance?
A) It has no effect on performance
B) A poor choice can lead to many collisions and slower performance
C) A good choice guarantees constant time operations
D) Both B and C
Answer: D) Both B and C
What would be an ideal characteristic of a hash function?
A) It should be easy to reverse
B) It should produce similar hash values for similar inputs
C) It should spread out hash values uniformly
D) It should depend heavily on the input format
Answer: C) It should spread out hash values uniformly
What is a potential issue with using a simple additive hash function?
A) It can lead to poor distribution of hash values
B) It is too complex to implement
C) It is not deterministic
D) It requires too much memory
Answer: A) It can lead to poor distribution of hash values
In string hashing, what does “dynamic resizing” refer to?
A) Adjusting the hash function
B) Changing the size of the input strings
C) Modifying the size of the hash table based on load factor
D) Resizing strings to fit within the hash values
Answer: C) Modifying the size of the hash table based on load factor
What is a common method to enhance the efficiency of a hash table?
A) Using a fixed hash function
B) Ensuring a low load factor
C) Ignoring collisions
D) Using longer strings
Answer: B) Ensuring a low load factor
Which of the following best describes “universal hashing”?
A) A hash function that guarantees no collisions
B) A family of hash functions from which one is chosen at random
C) A hash function that is only applicable to integers
D) A hash function that uses no randomness
Answer: B) A family of hash functions from which one is chosen at random
What is the effect of a high load factor on a hash table?
A) Increased speed
B) More collisions and slower performance
C) Better memory utilization
D) Increased size
Answer: B) More collisions and slower performance
What is a common application of rolling hash in algorithms?
A) String sorting
B) Text searching
C) Data compression
D) Data encryption
Answer: B) Text searching
Basic Concepts
Non-Linear Data Structures MCQs
Sorting and Searching Algorithms MCQs
- Data Structures MCQs 1
- Data Structures MCQs 2
- Data Structures MCQs 3
- Data Structures MCQs 4
- Data Structures MCQs 5
- Stacks Solved MCQs
- Queues MCQs
- pointer mcqs
- Array MCQs