[Algorithm-search one] sequential search

Source: Internet
Author: User

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.

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.