Symbol table implementation (symbol tables implementations)

Source: Internet
Author: User

There are many ways to implement a symbol table, and here are a few of them.

Unordered (unsorted) array implementations

In this case, you do not need to change the array, the operation is executed on this array. In the worst case, insert, search, delete time complexity is O (n).

Sequential (sorted) array implementations

In this case we have the sorted keyword and the corresponding value.

Store by keyword in an array

Keys[i] is the key of the I-bit large (keyword)

Values[i] is the value of the first-bit large key

Since elements are stored sequentially in an array, finding an element can be a simple two-point search. In the worst case, the search time complexity is O (log n), and the insertion and deletion time complexity is O (n).

The implementation of the chain list in the chaotic sequence

Just need to have a list of two elements on the line. The time complexity of searching, inserting, and Deleting is O (n).

Sequential chain list Implementation

In this way, when we insert elements, we want to keep the primitives ' keywords in order (such as size order). Even if the list is sorted, worst-case insertions, deletions, and search operation times are all O (n).

Some other implementation methods:

Binary Tree Implementation

Balanced binary Tree Implementation

Ternary Search Implementation

Hash Table Implementation

Comparison of the implementation methods of various symbol tables
Implementation Search Insert Delete
Unordered Array N N N
Ordered Array Log n N N
Unordered List N N N
Ordered List N N N
Binary Search Trees (O (log n) on average) Log n Log n Log n
Balanced Binary Search Tree Log n Log n Log n
Ternary Search Log n Log n Log n
Hashing (O (1) on average 1 1 1

Symbol table implementation (symbol tables implementations)

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.