What is Hash Table?
Turn a key into a bucket number to store and find values in constant time.
Type a tool name, format or task
Turn a key into a bucket number to store and find values in constant time. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Turn a key into a bucket number to store and find values in constant time. Compute a hash number from the key. Use hash % bucket count to pick a bucket. Store the item there; if the bucket already has items (a collision) chain it after them. Time complexity: O(1) average. Space complexity: O(n). JavaScript objects, Map and Set. Understanding hashing explains why key lookups are fast and why collisions matter.
Turn a key into a bucket number to store and find values in constant time.
Time: O(1) average. Space: O(n).
JavaScript objects, Map and Set. Understanding hashing explains why key lookups are fast and why collisions matter.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
A hash table turns a key into a number (a hash) and uses it to jump straight to a bucket. Here the hash is the sum of the letter codes, modulo 5 buckets.
function hash(key, size) {let sum = 0;for (const ch of key) sum += ch.charCodeAt(0);return sum % size;}function set(table, key, value) {const bucket = table[hash(key, table.length)];bucket.push([key, value]);}function get(table, key) {const bucket = table[hash(key, table.length)];for (const [k, v] of bucket) if (k === key) return v;}
Tip: use the arrow keys to step and the space bar to play or pause.