Hash table

Introduction to Hash table

A Hash Table is a data structure that stores key-value pairs using a hash function to map keys to array indices for fast access.

Key Properties

Example in C++


#include <iostream>
#include <unordered_map>
using namespace std;

int main() {
    unordered_map<string, int> marks;

    marks["Alice"] = 90;
    marks["Bob"] = 80;

    cout << "Alice's marks: " << marks["Alice"] << endl;

    // Check if key exists
    if (marks.count("Bob"))
        cout << "Bob is present." << endl;

    return 0;
}

    

Learning resource

Readings Hash table
Videos Hash table