42 Lecture

CS301

Midterm & Final Term Short Notes

Collision

Collision in computer science refers to the scenario where two or more data items end up at the same memory location or slot in a data structure such as a hash table or an array. Collisions can cause a significant impact on the performance of th


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is collision in computer science? A. A situation where a program crashes B. A situation where two or more data items end up at the same memory location C. A situation where a program encounters a syntax error D. A situation where a program encounters a logical error Answer: B

  2. Which of the following data structures can experience collisions? A. Linked lists B. Arrays C. Hash tables D. Stacks Answer: C

  3. What is the impact of collisions on data structure performance? A. Faster access times B. Slower access times C. Increased data security D. Decreased memory consumption Answer: B

  4. What is chaining in collision handling? A. Resolving a collision by allocating new memory B. Resolving a collision by reorganizing the data structure C. Resolving a collision by deleting the collided data item D. Resolving a collision by linking the collided data items together Answer: D

  5. Which of the following is a disadvantage of chaining? A. It requires less memory B. It can result in longer access times C. It can result in data loss D. It requires more processing power Answer: B

  6. Which of the following is a disadvantage of open addressing? A. It requires more memory B. It can result in longer access times C. It can result in data loss D. It requires more processing power Answer: A

  7. What is linear probing in open addressing? A. Resolving a collision by rehashing the key B. Resolving a collision by allocating new memory C. Resolving a collision by searching sequentially for an empty slot D. Resolving a collision by randomly selecting a new memory location Answer: C

  8. What is quadratic probing in open addressing? A. Resolving a collision by rehashing the key B. Resolving a collision by allocating new memory C. Resolving a collision by searching sequentially for an empty slot D. Resolving a collision by incrementing the probe step by a quadratic function of the previous step Answer: D

  9. Which of the following is an example of a hash function? A. Sorting algorithm B. Linear search C. Bubble sort D. MD5 Answer: D

  10. What is the purpose of a hash function in collision handling? A. To reduce the number of collisions B. To increase the number of collisions C. To increase the memory consumption D. To decrease the access time Answer: A



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is collision in hash tables? Answer: Collision in hash tables occurs when two or more keys hash to the same index.

  2. How can we resolve collisions in open addressing? Answer: In open addressing, we resolve collisions by probing through the table and finding an empty slot to store the collided key.

  3. What is chaining in hash tables? Answer: Chaining is a technique used to resolve collisions in hash tables by storing the collided keys in a linked list at the hashed index.

  4. What is the load factor in hash tables? Answer: The load factor in hash tables is the ratio of the number of keys stored to the total number of slots in the hash table.

  5. What is rehashing in hash tables? Answer: Rehashing is the process of increasing the size of the hash table and redistributing the keys in order to reduce the load factor and maintain O(1) average time complexity.

  6. What is the worst-case time complexity of hash table operations? Answer: The worst-case time complexity of hash table operations is O(n), where n is the number of keys stored in the hash table, but in practice, hash tables have an average-case time complexity of O(1).

  7. What is the difference between linear probing and quadratic probing? Answer: Linear probing resolves collisions by probing the next slot in the table, while quadratic probing uses a quadratic function to determine the next slot to probe.

  8. How do you calculate the load factor of a hash table? Answer: The load factor of a hash table is calculated by dividing the number of keys stored by the number of slots in the table.

  9. What is the worst-case time complexity of searching in a hash table? Answer: The worst-case time complexity of searching in a hash table is O(n), but in practice, searching has an average-case time complexity of O(1).

  10. What is a perfect hash function? Answer: A perfect hash function is a hash function that generates unique indices for every key, so there are no collisions.

Collision is a common problem in hash tables where two different keys produce the same hash value, leading to a collision. To handle collisions, there are different techniques such as open addressing and chaining. Open addressing is a method in which an algorithm probes different locations in the table to find an empty slot to store the key-value pair. Linear probing, quadratic probing, and double hashing are some of the techniques used in open addressing. Chaining is a method in which each slot of the hash table is a pointer to a linked list, which contains all keys that have mapped to the same slot. Collision resolution techniques are crucial to the efficiency and effectiveness of hash tables. A good hash function and an efficient collision resolution technique can ensure that the hash table performs well and doesn't take up too much memory. Collision can lead to performance degradation and even failure if not handled correctly. Therefore, it is essential to understand collision resolution techniques and choose the right technique for the given use case.