What is Hashmap?

A hashmap (also called a hash table) is a data structure that stores key → value pairs and supports fast insertion, deletion, and lookup on average.

In Python, the built-in implementation is dict.

mp = {"name": "Ali", "age": 20}
print(mp["name"])  # Ali

Introduction :

  1. Key → Value mapping

    Each key points to exactly one value.

  2. Fast average operations

    Insert / search / delete are typically O(1) average.

  3. Keys are unique

    If you insert the same key again, the value gets overwritten.

  4. Hashing

    A hash function converts a key into an index (bucket).

  5. Collision handling

    If two keys map to the same bucket, the hashmap handles it using techniques like chaining or open addressing.

Core idea (Hashing)

A hash function takes a key and produces an integer index.

index = hash(key) % table_size

Memory representation (Conceptual)

A hashmap uses an internal array of buckets.