Algorithm research: Static lookup table

Source: Internet
Author: User
Tags comparison

A lookup table (search table) is a collection of data elements (or records) of the same type. A keyword (key) is the value of a data item in a data element, also known as a key value, that can represent a data element, or it can identify a record's data item (field), called a key code. If this keyword uniquely identifies a record, this keyword is called the primary keyword (primary key). And for those who can identify multiple data elements (or records) of the keyword, called the secondary key (secondary key), the secondary keyword can also be understood not to uniquely identify a data element (or record) of the keyword, its corresponding data item is the secondary key code.

Lookup (searching) is a data element (or record) in a lookup table that is equal to a given value, based on a given value.

The lookup table is divided into two main types: static lookup table and dynamic lookup table.

Static lookup tables (static search table): Lookup tables for only lookup operations, the main actions are:

(1) query whether a "specific" data element is in the lookup table.

(2) Retrieve a "specific" data element and various attributes.

Dynamic Search Table: Inserts a data element that does not exist in the lookup table while in the lookup, or deletes a data element that already exists from the lookup table.

(1) Insert data element when searching.

(2) Delete data elements when searching.

This article first says static lookup table.

A, sequential table lookup

Sequential lookup (sequential search) is also called Linear lookup, is the most basic search technology, its search process is: from one (or last) record in the table, record the keyword and the given value of the comparison, if a record of the keyword and the given value is equal, then find success, Find the records that are being searched; if the key and the given value are not equal when the last (or first) record is not the same, the lookup is not successful in the table.

Second, ordered table lookup

1, binary search

Binary lookup (Binary search) technology, also known as binary search. The premise is that the records in the linear table must be in order (usually from small to large order), and the linear table must be stored sequentially. The basic idea of binary lookup is: In ordered table, take intermediate record as comparison object, if the given value is equal to the key of the intermediate record, the lookup succeeds; If the given value is less than the middle record's keyword, the search continues in the left half of the intermediate record, and if the given value is greater than the middle record's keyword, the search continues in the right half of the intermediate record. Repeat the process until the lookup succeeds, or if all the lookup areas are not logged, the lookup fails.

2, interpolation search

Interpolation lookup (interpolation search) is based on the keyword to find the key and lookup table of the largest minimum record of the search method, the core is the interpolation of the calculation formula (Key-a[low])/(A[high]-a[low)).

3, Fibonacci Search

The core of the Fibonacci lookup (Fibonacci search) algorithm is

1 when key = A[mid], the search is successful;

2 when key < A[mid], the new range is the low to the first mid-1, at this time the number of the range is f[k-1]-1.

3 when key > A[mid], the new range is the first m+1 to the first high, at this time the number of the range is f[k-2]-1.

As shown in Figure 8-4-13.

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.