【Data Structure Learning Record 24】——Search

Zero. Foreword

This chapter (search series) only gives concepts, and does not implement it in code. It is more mathematical analysis.

1. Overview of Finding

查找表It is a collection of data elements (or records) of the same type.
Now search generally has four operations

  1. Query 特定的whether an element is in the lookup table.
  2. Retrieve 特定的various attributes of an element.
  3. In the lookup table, insert a data element.
  4. In the lookup table, delete a data element.
    If our lookup table has only the first two operations, then this type of table is called 静态查找表.
    If there are additions and deletions in the search process, then this type of table is called 动态查找表.

Two. Concept

关键字(Key)It is the specific value of a data item in the data element.
If this 关键字can uniquely identify a record, then the key is called . 主关键字(Primary Key)
If this 关键字can identify several records, it is called 次关键字(Secondary Key).
When the data element has only one data item, the key is the value of the data element. (For example, a sequence table composed of structures, this is not the case.)
查找According to a specific value, determine a record or data element whose key is equal to the given value in the lookup table. If such a record exists in the table, it should 查找be yes 成功. The search result can give a record of the entire information, or give its index value in the table. If there is no record with the key equal to the given value in the table, then 查找不成功. At this time, you can give a 空记录or 空指针or 非法的标记.

3. Performance analysis

As we mentioned earlier, there are three metrics to measure an algorithm:

  1. time complexity.
  2. Space complexity.
  3. Other properties of the algorithm.

But in the search, we usually use 其关键字the average of the number of records compared with the given value as the basis for measuring the quality of the search algorithm.
Definition: In order to determine the position of the record in the lookup table, the expected value of the number of keywords that need to be compared with the given value is called "the search algorithm when the search is successful 平均查找长度".

Four. Static search

Five. Dynamic search

Six. Hash table

Write later

Guess you like

Origin blog.csdn.net/u011017694/article/details/111239458