DEV Community

Ehab Hussein
Ehab Hussein

Posted on

Day 1 of #100DaysOfCode Hash Tables

πŸ” Efficient Data Retrieval: Arrays offer O(1) access, but the linear search takes O(n). Hash tables leverage hash functions for O(1) insertion and access.

Note: hash function: Is a function that spits out the index of an available slot of the list to to insert new data or to retrieve data if data exists.

βš™οΈ Dynamic Data Management: Arrays require shifting elements for insertion, while linked lists demand traversal. Hash tables, through hash functions, ensure O(1) insertion regardless of position.

πŸ”‘ Key-Value Pairing: Hash tables resolve the search complexity (O(n)) by associating each element with a key. A hash function maps the key to its location, facilitating rapid retrieval.

βž– Smart Removal Technique: Additionally, hash tables employ intelligent removal methods. By leveraging the key, removal becomes an O(1) operation, maintaining efficiency.

πŸ”— Collision Resolution: I also explored collision scenarios where different keys map to the same location, leading to chaining and linear probing techniques. Chaining involves linking collided elements in a linked list, while linear probing explores adjacent slots for placement.

hash_table.h:
Image description

bucket.h (slots of the table)

Image description

person.h (value of the table)

Image description

100daysofALXSE

Top comments (0)