One Hash tables

Source: Internet
Author: User

One Hash tables?

?

Many applications require a dynamic set that supports only the dictionary operations INSERT, SEARCH, and DELETE.

For example, a compiler so translates a programming language maintains a symbol table, in which the keys of elements is arbitrary character strings corresponding to identifiers in the language.

?

A Hash table generalizes the simpler notion of an ordinary array. Directly ad-dressing into a ordinary array makes effective use of we ability to examine a arbitrary position in an arr Ay in O (1) time.?

?

a Hash the table is extended by a simple ordinary column. Direct addressing allows an ordinary column to check any position in the O (1) time.

?

11.1 direct-address tables?

Direct addressing is a simple technique this works well then the universe U of keys is reasonably small.

Direct addressing is a simple technique. when the interval of the keyword is the right hour, it works fine.

?

?

To represent the dynamic set, we use a array, or direct-address table, denoted by T [0: M-1],?in which each position, or Slot, corresponds to a key in the Uni-verse U.

?

11.2 Hash tables?

?

With direct addressing, a element with key k is the stored in slot K. With hashing, this element is the stored in slot h.k/; That's, we use a hash function h to compute the slots from the key K.

Here, h maps the universe U's keys into the slots of a hash table t[0. M-1]:

h:u->{0,1,..., M-1}

?

We say that a element with the key K hashes to slot h.k/; We also say that h.k/is the hash value of key K.

?

?

?

There is one hitch:two keys could hash to the same slot. We call this situation a collision.

?

Collision resolution by chaining

In chaining, we place all the elements that hashes to the same slots into the same linked list

?

The dictionary operations on a hash table T is easy to implement when collisions is resolved by chaining?

?

11.3 Hash functions?

In this section, we discuss some issues regrading the design of good hash functions and then?? Present three schemes for their creation. The schemes, hashing by division and hashing by multiplication, is heuristic in nature, whereas?? The third scheme, universal hashing, uses randommization to provide provably good performance.

11.3.1 The Division method

H (k) =k mod m?

11.3.2 the multiplication method?

The multiplication method for creating hashes functions operates in and steps. First, we multiply the key k by a constant A in the range 0 < A < 1 and extract the

Fractional part of KA. Then, we multiply this value by M. and take the "the floor of the" result. In short, the hash function is

These two functions are the simplest.

Hash table The most important thing is to find a hash function, let it try to avoid or less points Collision .

11.4 Open addressing?

?

In open addressing, all elements occupy the hash table itself. That's, each table entry contains either an element of the dynamic set or nil. When searching-a element, we systematically examine table slots until either we find the desired element or we have a Scertained the element is not in the table. No lists and

No elements is stored outside the table, unlike in chaining.

?

The advantage of open addressing?? Is that?? It avoids pointers altogether.?

The advantage of open addresses is that pointers are completely avoided.

?

Instead of following pointers, we compute the sequence of slots to be examined.

?

instead of pointers we calculate slots? the sequence to check.

?

The hash function becomes:

With open addressing, we require that for every key K, the probe sequence?

Be a permutation of <0,1,,.. M-1>

?

The algorithm for searching for key K probes the same sequence of slots that the insertion algorithm examined when key K W As inserted.

?

?

?

In our analysis, we assume uniform hashing:the probe sequence of each key are equally likely to being any of the M!permutati ONS of <0,1,2,m-1>.

We'll examine three commonly used techniques to compute the probe sequences required for open addressing:linear Probin G, quadratic probing, and double hashing.

Linear probe, Square probe, double probe.

?

Linear probing?

Given an ordinary hash function h ': u->{0,1,m-1}, which we refer to as an auxiliary hash function, the method of linear Probing uses the hash function?

?

?

Double hashing?

Double Hashing offers one of the best methods available for open addressing be-cause the permutations produced has many Of the characteristics of randomly chosen permutations. Double hashing uses a hash function of the form

?

?

?

?

?

?

?

One Hash tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.