# 计算机代写|算法分析作业代写Introduction to Algorithms代考|COSC240

## 计算机代写|算法分析作业代写Introduction to Algorithms代考|Hash functions for hierarchical memory models

This section illustrates an approach for designing efficient hash tables in a modern computer system having a memory hierarchy.

Because of the memory hierarchy, linear probing is a good choice for resolving collisions, as probe sequences are sequential and tend to stay within cache blocks. But linear probing is most efficient when the hash function is complex (for example, 5 -independent as in Theorem 11.9). Fortunately, having a memory hierarchy means that complex hash functions can be implemented efficiently.

As noted in Section 11.3.5, one approach is to use a cryptographic hash function such as SHA-256. Such functions are complex and sufficiently random for hash table applications. On machines with specialized instructions, cryptographic functions can be quite efficient.
Instead, we present here a simple hash function based only on addition, multiplication, and swapping the halves of a word. This function can be implemented entirely within the fast registers, and on a machine with a memory hierarchy, its latency is small compared with the time taken to access a random slot of the hash table. It is related to the RC6 encryption algorithm and can for practical purposes be considered a “random oracle.”

Let $w$ denote the word size of the machine (e.g., $w=64$ ), assumed to be even, and let $a$ and $b$ be $w$-bit unsigned (nonnegative) integers such that $a$ is odd. Let $\operatorname{swap}(x)$ denote the $w$-bit result of swapping the two $w / 2$-bit halves of $w$-bit input $x$. That is,
$\operatorname{swap}(x)=(x \gg(w / 2))+(x \lll(w / 2))$ “left shift.” Define
$f_a(k)=\operatorname{swap}\left(\left(2 k^2+a k\right) \bmod 2^w\right)$
Thus, to compute $f_a(k)$, evaluate the quadratic function $2 k^2+a k$ modulo $2^w$ and then swap the left and right halves of the result.

Let $r$ denote a desired number of “rounds” for the computation of the hash function. We’ll use $r=4$, but the hash function is well defined for any nonnegative $r$. Denote by $f_a^{(r)}(k)$ the result of iterating $f_a$ a total of $r$ times (that is, $r$ rounds) starting with input value $k$. For any odd $a$ and any $r \geq 0$, the function $f_a^{(r)}$, although complicated, is one-to-one (see Exercise 11.5-1). A cryptographer would view $f_a^{(r)}$ as a simple block cipher operating on $w$-bit input blocks, with $r$ rounds and key $a$.

## 计算机代写|算法分析作业代写Introduction to Algorithms代考|The wee hash function for variable-length inputs

Sometimes inputs are long-more than one $w$-bit word in length-or have variable length, as discussed in Section 11.3.5. We can extend the wee hash function, defined above for inputs that are at most single $w$-bit word in length, to handle long or variable-length inputs. Here is one method for doing so.

Suppose that an input $k$ has length $t$ (measured in bits). Break $k$ into a sequence $\left\langle k_1, k_2, \ldots, k_u\right\rangle$ of $w$-bit words, where $u=\lceil t / w\rceil, k_1$ contains the least-significant $w$ bits of $k$, and $k_u$ contains the most significant bits. If $t$ is not a multiple of $w$, then $k_u$ contains fewer than $w$ bits, in which case, pad out the unused high-order bits of $k_u$ with 0-bits. Define the function chop to return a sequence of the $w$-bit words in $k$ :
$\operatorname{chop}(k)=\left\langle k_1, k_2, \ldots, k_u\right\rangle$
The most important property of the chop operation is that it is one-toone, given $t$ : for any two $t$-bit keys $k$ and $k^{\prime}$, if $k \neq k^{\prime}$ then $\operatorname{chop}(k) \neq$ $\operatorname{chop}\left(k^{\prime}\right)$, and $k$ can be derived from $\operatorname{chop}(k)$ and $t$. The chop operation also has the useful property that a single-word input key yields a singleword output sequence: $\operatorname{chop}(k)=\langle k\rangle$.

With the chop function in hand, we specify the wee hash function $h_{a, b, t, r}(k)$ for an input $k$ of length $t$ bits as follows:
$h_{a, b, t, r}(k)=\operatorname{WEE}(k, a, b, t, r, m)$,
where the procedure WEE defined on the facing page iterates through the elements of the $w$-bit words returned by chop $(k)$, applying $f_a^r$ to the sum of the current word $k_i$ and the previously computed hash value so far, finally returning the result obtained modulo $m$. This definition for variable-length and long (multiple-word) inputs is a consistent extension of the definition in equation (11.7) for short (single-word) inputs. For practical use, we recommend that $a$ be a randomly chosen odd $w$-bit word, $b$ be a randomly chosen $w$-bit word, and that $r=4$.

Note that the wee hash function is really a hash function family, with individual hash functions determined by parameters $a, b, t, r$, and $m$. The (approximate) 5 -independence of the wee hash function family for variable-length inputs can be argued based on the assumption that the 1-word wee hash function is a random oracle and on the security of the cipher-block-chaining message authentication code (CBC-MAC), as studied by Bellare et al. [42]. The case here is actually simpler than that studied in the literature, since if two messages have different lengths $t$ and $t$ ‘, then their “keys” are different: $a+2 t \neq a+2 t{ }^{\prime}$. We omit the details.

# 算法分析代考

## 计算机代写|算法分析作业代写Introduction to Algorithms代考|The wee hash function for variable-length inputs

chop 操作最重要的特性是它是一对一的，给定 $t$ : 对于任意两个 $t$ 位密钥 $k$ 和 $k^{\prime}$ ，如果 $k \neq k^{\prime}$ 然后 $\operatorname{chop}(k) \neq \operatorname{chop}\left(k^{\prime}\right)$ ， 和 $k$ 可以从 $\operatorname{chop}(k)$ 和t. chop 操作还有一个有用的属性，即单字输入键产生单 字输出序列: $\operatorname{chop}(k)=\langle k\rangle$.

myassignments-help数学代考价格说明

1、客户需提供物理代考的网址，相关账户，以及课程名称，Textbook等相关资料~客服会根据作业数量和持续时间给您定价~使收费透明，让您清楚的知道您的钱花在什么地方。

2、数学代写一般每篇报价约为600—1000rmb，费用根据持续时间、周作业量、成绩要求有所浮动(持续时间越长约便宜、周作业量越多约贵、成绩要求越高越贵)，报价后价格觉得合适，可以先付一周的款，我们帮你试做，满意后再继续，遇到Fail全额退款。

3、myassignments-help公司所有MATH作业代写服务支持付半款，全款，周付款，周付款一方面方便大家查阅自己的分数，一方面也方便大家资金周转，注意:每周固定周一时先预付下周的定金，不付定金不予继续做。物理代写一次性付清打9.5折。

Math作业代写、数学代写常见问题

myassignments-help擅长领域包含但不是全部: