FlowLab Logo

Hash Table Search Visualizer

SlowFast
59
(7)
717
(11)
Probe Index
Hash Index
Target Value
Found
Other
Empty Slot
Operation Logs
No operations yet
Algorithm Info
Time Complexity: O(1) average, O(n) worst (collisions)
Space Complexity: O(n)
Best Case: O(1) - no collision
Worst Case: O(n) - all collisions
How it works: Uses hash function to map key to index. Collisions handled by linear probing.
When to use: Fast access, insert, search for key-value pairs.
Implementation
function hashTableSearch(table, target) {
  const capacity = table.length;
  let hashIdx = target % capacity;
  let probeIdx = hashIdx;
  let tries = 0;
  while (tries < capacity) {
    if (table[probeIdx] && table[probeIdx].key === target) return probeIdx;
    if (table[probeIdx] === null) break;
    probeIdx = (probeIdx + 1) % capacity;
    tries++;
  }
  return -1;
}