Algorithm-sequential search
Search-is one of the most common data operations and one of the core operations of the data structure. Its importance is self-evident. Sequential search is the most familiar search policy. For small-scale data, sequential search is a good choice.1. Sequential search:Core: Start from the first element of the data and start a comparison until the target data is found or the search fails.1. Start from the first element in the table and compare it with the keyword in sequence.2. If an element matches a keyword, the search is successful.3. If the last element does not match a keyword, the search fails.Starting with the first Keyword:
Comparison with keywords in sequence:Ordered search is not required for sorting the elements in a table. These elements can be sorted in any way in the table, which makes sequential search highly adaptive. The implementation of sequential search is simple. The sample code is as follows:
The example program is as follows:2. Time Complexity:The average number of matching keywords in sequential search is half of the table length, and the time complexity is O (n ).3. Evaluation of sequential search:The advantage of sequential search is that there is no requirement on the table, and data insertion can be completed within O (1. The disadvantage is that the time complexity is large, the data size is large, and the efficiency is low.