From: http://student.zjzk.cn/course_ware/data_structure/web/chazhao/chazhao9.1.1.htm
Introduction to this chapter
Because search operations are frequently used, they are involved in almost any computer system software and application software. Therefore, when the data volume involved in the problem is large, the efficiency of searching methods is particularly important. This is especially true in some real-time query systems. Therefore, this chapter systematically discusses various search methods and compares the advantages and disadvantages of various search methods by analyzing their efficiency.
Basic Search concepts
1. Search for tables and search
Generally, it is assumed that the object to be searched is a table or file composed of a group of nodes, and each node is composed of several data items. Assume that each node has a keyword that uniquely identifies the node.
The search definition is: Given A value K, find the node with the keyword equal to the given value K in the table containing N nodes. If the node is found, the query is successful, and the information of the node or the location of the node in the table is returned. Otherwise, the query fails and related instructions are returned.
2. query the Data Structure Representation of a table
(1) Dynamic and Static search tables
If you modify a table (such as insert or delete) while searching, the corresponding table is called a dynamic searching table. Otherwise, it is called a static query table.
(2) internal search and external search
Similar to sorting, search can also be divided into inner and outer searches. If the entire search process is in the memory, it is called the internal search; otherwise, if the external store needs to be accessed during the search process, it is called the external search.
3. Average search length ASL
The main operation of search operations is the comparison of keywords. Therefore, the average comparison times (also known as the average search length) to be executed for keywords in the search process are used as the criteria to measure the efficiency of a search algorithm.
The average search length ASL (average search length) is defined:
Where:
① N is the number of nodes;
② Pi is the probability of finding the I-th node. If not specifically stated, the search probability of each node is considered equal, that is
PL = P2... = Pn = 1/n
③ Ci is the number of comparisons required to locate the I-th node.
Note:
For simplicity, assume that the type of the keywords in the table is an integer:
Typedef int keytype; // The keytype should be defined by the user.
Go to: Basic Search concepts