Introduction to Algorithms (Open Addressing, Cryptographic Hashing)

Open addressing

Another approach to collisions

  • no chaining; instead all items stored in a table
  • one item per slot ⇒ m ≥ n
  • hash function specifies the order of slots to probe (try) for a key (for insert/search/delete), not just one slot; in math. notation:

We want to design a function h, with the property that for all k ∈ U:

        h : U × {0, 1,...,m − 1} → {0, 1,...,m − 1} , U = universal of keys, {} = trial count, {} = slot in table

        <h(k, 0), h(k, 1), . . . , h(k, m − 1)> is a permutation of 0, 1, . . . , m − 1

Insert(K, V): Keep probing until an empty slot is found; Insert item when found.

Search(K): As long as the slots encountered are occupied by keys != k, keep probing until you either encounter k or find an empty slot

Delete(K): 

  • can’t just find item and remove it from its slot (i.e. set T[h(k, i)] = None)
  • replace item with special flag: “DeleteMe”, which Insert treats as None but Search doesn’t

Probing strategies

Linear Probing

h(k, i) = (h'(k) + i) mod m where h'(k) is ordinary hash function

  • clustering - cluster: consecutive group of occupied slots as clusters become longer, it gets more likely to grow further
  • can be shown that for 0.01 < α < 0.99 say, clusters of size Θ(log n).

Double Hashing

 h(k, i) =(h1(k) +i·h2(k)) mod m where h1(k) and h2(k) are two ordinary hash functions.

  • actually hit all slots (permutation) if h2(k) is relatively prime to m for all k
  • e.g. m = 2r , make h2(k) always odd

Uniform Hashing Assumption

Each key is equally likely to have any one of the m! permutations as its probe sequence

  • not really true
  • but double hashing can come close

Analysis

Suppose we have used open addressing to insert n items into a table of size m. Under the uniform hashing assumption, the next operation has expected cost of 1 / (1 - α), where α = n/m (<1)

Every trial, success with probability at least p. Expected Number of trials for success? 1/p = 1/(1-α)

Cryptographic Hashing

A cryptographic hash function is a deterministic procedure that takes an arbitrary block of data and returns a fixed-size bit string, the (cryptographic) hash value, such that an accidental or intentional change to the data will change the hash value. The data to be encoded is often called the message, and the hash value is sometimes called the message digest or simply digest.

The ideal cryptographic hash function has the properties listed below. d is the number of bits in the output of the hash function. You can think of m as being 2^d. d is typically 160 or more. These hash functions can be used to index hash tables, but they are typically used in computer security applications.

Desired Properties

  1. One-Way(OW): given h(x) = Q, it is very hard to find x satisfy h(x) = Q
  2. Collision-resistance (CR): Infeasible to find x, x', s.t. x = x' and h(x) = h(x'). This is a collision, two input values have the same hash.
  3. Target collision-resistance (TCR): Infeasible given x to find x' = x s.t. h(x) = h(x').
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值