UPDATED_collision and collision resolution

Duration: 8 min

This video lesson is available to enrolled students.

Enroll to watch — DSA using Java

AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This lecture segment introduces the fundamental concept of collision in hashing, where two distinct keys produce identical hash addresses. The instructor begins by defining this scenario and visually demonstrating it using a whiteboard representation of a hash table divided into slots. The core problem addressed is how to manage these collisions effectively, leading to a discussion on two primary resolution strategies: chaining and open addressing. The lecture specifically details the mechanics of linear probing, a type of open addressing, highlighting its operational procedures for insertion and search. A critical technical nuance is emphasized regarding the deletion operation in linear probing, where simply removing an element can disrupt search chains for subsequent items. Consequently, the instructor explains that deleted slots must be marked with a special 'deleted' status rather than being treated as empty, ensuring that searches continue past them to find valid keys.

Chapters

  1. 0:00 2:00 00:00-02:00

    The video opens with the instructor defining collision in hashing, explicitly stating on screen that 'It is possible that two different set of keys K1 and K2 will yield the same hash address.' The instructor draws a large box to represent a hash table and divides it into slots or buckets. Visual evidence includes the instructor writing 'D' as a potential key and drawing mapping arrows for keys 'A' and 'Z' to the same location. The demonstration shows a collision where key 'A' maps to index 5 and key 'Z' also maps to index 5, which is then resolved by chaining to another slot containing 'BT'. This section establishes the foundational problem of hash collisions and introduces a visual method for understanding how multiple keys can map to the same index.

  2. 2:00 5:00 02:00-05:00

    The lecture transitions to collision resolution techniques, specifically introducing Open Addressing (closed hashing). The instructor explains that in this method, all elements are stored directly within the hash table itself. A key constraint highlighted is that 'the table size must always be greater than or equal to the total number of keys.' The instructor lists three specific types of open addressing: 'linear probing, quadratic probing, double hashing.' A critical note is displayed on screen stating, 'Irrespective of how good a hash function is, collisions are bound to occur.' The instructor underlines key terms like 'probing' and emphasizes that collisions cannot be entirely avoided. This section sets the theoretical framework for open addressing before diving into specific algorithms.

  3. 5:00 8:27 05:00-08:27

    The final segment focuses on the detailed mechanics of linear probing. The instructor explains that this method 'searches the table sequentially starting at the position given by the hash function.' The slide text confirms that operations can be implemented in 'constant expected time' under random hash functions. A significant portion of the lecture is dedicated to the deletion operation, described as 'interesting' because simply deleting a key can cause search failures. The instructor illustrates that if a slot is truly empty, the search stops prematurely, potentially missing keys stored further down the probe sequence. The solution presented is to mark slots of deleted keys specially as 'deleted.' This allows the insert operation to reuse these slots and ensures the search operation does not stop at a deleted slot, continuing instead until it finds the matching key or an actual empty cell. The video concludes with a 'Thanks for watching' screen.

The lecture systematically progresses from defining the problem of hash collisions to presenting specific resolution strategies. The initial visual demonstration using keys 'A' and 'Z' mapping to the same index effectively illustrates why collision resolution is necessary. The distinction between chaining and open addressing is established, with a specific focus on linear probing as the primary example of closed hashing. The most critical technical takeaway is the handling of deletions in linear probing; unlike simple array deletion, hash table entries marked as deleted must remain part of the probe sequence to maintain data integrity. This ensures that searches for keys located after a deleted entry do not terminate incorrectly at the empty slot. The instructor emphasizes that while hash functions aim to distribute keys evenly, collisions are inevitable, making the choice of resolution strategy crucial for performance and correctness.

Loading lesson…