Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ bazel-testlogs
bazel-*
*.md2
test_data
.DS_Store
MODULE.bazel
MODULE.bazel.*
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ A data structure is a data organization, management, and storage format that is
<a href="/concepts/general/set/README.md">Set</a>
</li>
<li>
<code>B</code> Hash Table
<a href="/concepts/cpp/hash_table.md"><code>cpp🐀</code></a>
<a href="/concepts/python/hash_table.md"><code>py🐍</code></a>
<code>B</code>
<a href="/concepts/general/hash-table/README.md">Hash Table</a>
</li>
<li>
<code>B</code> Heap
Expand Down
41 changes: 41 additions & 0 deletions concepts/general/hash-table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Hash Table

*See implementation in*
[C++](../../cpp/hash_table.md),
Java,
[Python](../../python/hash_table.md),
Typescript

A hash table, also known as a hash map, is a fundamental data structure used to store key-value pairs. It uses a hash function to compute an index into an array of slots or buckets, from which the desired value can be found. This mechanism allows for efficient data retrieval, making hash tables an essential component in the implementation of associative arrays.

## Hash Table Operations

Key operations available in a hash table include:

- `Insert`: Adds a new key-value pair to the hash table.
- `Search`: Retrieves a value associated with a specific key.
- `Delete`: Removes a key-value pair from the hash table.

## How Hash Table Works

The process involves:

1. **Hashing**: Applying a hash function to a key to compute an index for storing values in the table.
2. **Collision Handling**: Since multiple keys may hash to the same index, methods like chaining or open addressing are used to resolve collisions.

## Advantages of Hash Tables

- **Efficiency**: Provides $O(1)$ average time complexity for search, insert, and delete operations.
- **Dynamic Resizing**: Many implementations resize automatically to handle more elements.
- **Direct Key-Value Mapping**: Facilitates efficient data access and retrieval.

## Disadvantages of Hash Tables

- **Collisions**: Requires additional structures or algorithms to handle collisions, which can complicate the design.
- **Space Consumption**: Some implementations may use extra space to manage collisions or maintain a low load factor.
- **Dependence on Hash Function**: The efficiency of a hash table is significantly influenced by the quality of its hash function.

## 🔗 Further Reading

- [Hash table](https://en.wikipedia.org/wiki/Hash_table), Wikipedia - A detailed explanation of hash tables, their operations, and their applications.
- ▶️ [Data Structures: Hash Tables](https://www.youtube.com/watch?v=shs0KM3wKv8&t=71s&ab_channel=HackerRank), HackerRank - A video tutorial that explains the concept of hash tables, including how they work and why they are useful.