• Julian's Globe

    HASH TABLE

    A hash table is a collection of items insterted, retrieved, and removed through the usage of a unique key per item. Data is stored as key-value pairs, where a key indicates a cell and the value is what is stored in that cell. You can think of a hash table like an array, except that you can use more than just integer numbers to refer to cells and the size of the hash table can keep growing (it is not fixed). They are particularly useful when you need to store data via some special type of indicator that immediately points to the cell it needs, such as by using a unique string.

    For example, let's say that I want a data structure storing my friends' favorite video game. We could use the first name of my friends as the key, and their favorite video game as the value. My hash table would look like the following:


    # Python code snippet

    friends_info = {}
    friends_info['Mike'] = 'Wii sports'
    friends_info['Carl'] = 'Fortnite'
    friends_info['James'] = 'Call of Duty: Mobile'
    print(friends_info['Mike']) # prints Wii sports