Several concepts are distinguished: dictionary, direct-address tables, and hash tables

Source: Internet
Author: User

Dictionary is an abstract data type used to store data items that can be indexed by key. Basic operations include insertion, search, and deletion. It is a relatively broad concept and does not specify specific implementation, such as what data structure is used to store data items at the underlying layer. Therefore, as long as each data item stored is a pair (Key, value) and can be indexed to this item with key, such a data type can be called dictionary.

 

Both direct-address tables and hash tables are specific implementation methods of dictionary. Direct-address tables is actually a normal array. The K entry of the array is only used to store data items whose key value is K. Obviously, to apply such a data structure, you must reserve an array for each possible key value. Therefore, it is only applicable when the key value set is small. Although direct-address tables seems to be a waste of memory, it also has its advantages: the time complexity of insert, search, and delete operations is O (1 ).

 

Hash Tables is an effective implementation of dictionary. It solves the problem that direct-address tables is not applicable when the key-value set is large. Assume that the u table shows a set of all possible key values. k indicates the set of key values to be stored. When | u | is much larger than | K |, hash tables only allocates data table items proportional to | K | size, and then maps K to each table item through the hash function. Hash Tables maps key values with a large value range to a small set, which greatly saves storage space, but also introduces collision, that is, when several key values are mapped to the same table item. Due to the complexity of collision processing, the time complexity of operations such as search and deletion is often no longer O (1), or even O (n) in the worst case) (N = | K | ). However, in practice, by selecting an appropriate hash function, the time complexity of the above operations can often be controlled close to O (1 ).

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.