Find
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
- Query
特定的
whether an element is in the lookup table. - Retrieve
特定的
various attributes of an element. - In the lookup table, insert a data element.
- 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:
- time complexity.
- Space complexity.
- 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