Bölüm 3 · Simülatör

Hash Search & Interpolation Search

← Bölüm 3

Hash Table Lookup h(k) = k mod 8

Chaining: each bucket keeps a list of keys.

Interpolation Search sorted array

pos = lo + ⌊(x − A[lo]) · (hi − lo) / (A[hi] − A[lo])⌋

    Hash Search & Interpolation Search

    Compare bucket lookup in a simple hash table with interpolation search on a sorted numeric array.

    How to use

    • Hash table: enter a key and press Find. The bucket h(k) = k mod 8 is highlighted and its chain is scanned from left to right. Insert appends a new key to its chain (to create collisions); Reset restores the initial table.
    • Interpolation search: enter a target and press Search to animate the probes, or Step to advance one probe at a time. The shaded cells are the current interval [lo, hi]. New Array draws a new sorted array (sometimes uniform, sometimes skewed).

    Hash search

    A hash function maps a key directly to a bucket. With a good hash function and load factor α = n / m, a lookup with separate chaining takes O(1 + α) time on average; in the worst case (all keys in one bucket) it is O(n).

    Interpolation search

    Instead of always probing the middle, it estimates the position of x from the values at the ends of the interval:

    pos = lo + ⌊(x − A[lo]) · (hi − lo) / (A[hi] − A[lo])⌋

    On uniformly distributed sorted data it needs O(log log n) probes on average; on skewed data it can degrade to O(n). Binary search, by comparison, always needs O(log n).