# Dictionary (Hash Map) (Hash Table)

## What is a Dictionary? :book:&#x20;

A **Dictionary** is a collection of key value pairs, meaning in order to access the elements (value) a corresponding element (key) must be known.

![Cluster Mailboxes Requiring a Key](/files/-MLp8rNy4PsAwDWNRTXJ)

## Cluster Mailbox :key2: :inbox\_tray: :outbox\_tray:  <a href="#cluster-mailbox" id="cluster-mailbox"></a>

To access, obtain, add, or remove mail (**value**), the information needed is the correct key (**key**).&#x20;

## Key -> Value :closed\_lock\_with\_key:&#x20;

**Keys** act as unique identifiers to their **values**.

* house key -> opens house :key2: -> :house:
* car key      -> opens car       :key:-> :red\_car:&#x20;

Similar to a physical key that says, "Honda" on it vs a key with a "house" carved into it. If i wanted to access my house. I would only need to find my house key which looks very different from my car key.&#x20;

## IRL Hypothetical :motorway:&#x20;

A customer goes into local automotive store, for a popped tire, not remembering the date when they bought the tire, or what the warranty was. The customer asks an employee if the popped tire is covered. The employee proceeds to look up the information associated with the customer. Normally the **Key** provided is a name and phone number, the employee can access the account aka **Value** and find relevant information about the tire purchased.&#x20;

## What is Hashing??? :no\_smoking:&#x20;

A **Hash** is a math-magical way to turn your dictionary key into a number.

**Hashing** is used because computers can find values faster using numbers (hashed keys) instead of letters (keys).&#x20;

* key -> (hashing) -> number -> value
* :key2:-> :heavy\_plus\_sign::heavy\_minus\_sign: ->    :1234:    -> :unlock:&#x20;

## Array vs Dictionary :apple: :tangerine:&#x20;

**Arrays** are used when the data needs to be ordered by number.

* Recipe for Apple Pie: 1. mix ingredients 2. bake 3. eat:notebook\_with\_decorative\_cover:&#x20;
* Finish times of a race: 1st place: 10 mins 2nd place: 11 mins, 3rd place 11.1 mins :checkered\_flag:

**Dictionaries** are used when the data needs to be accessed by name.&#x20;

* Recipe book: key = 'Apple pie' value = recipe, key = 'meatloaf' value = recipe, key = 'pizza' value = recipe :notebook\_with\_decorative\_cover:&#x20;
* Race contestants: key = 'Kyle' value= \[full name, age, weight, race number, starting time, finished time] :checkered\_flag:&#x20;

## Set :unicorn:&#x20;

A **Set** is a collection of items with no repeated items in the set. Each item in the set is a special & unique unicorn, just like you the reader. The reason sets are apart of the dictionary section is because sets are dictionary keys without values.&#x20;

* Ash Ketchum the pokemon trainer is trying to collect at least one of all the pokemon. &#x20;

:dragon:Adding the same pokemon to Ash's pokedex does not change the set:dragon:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ksmcclay.gitbook.io/no-code-computer-science/data-structures/hash-table-dictionary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
