Data structure Tutorial 30th class static lookup table (ii) ordered table lookup

Source: Internet
Author: User

Teaching Purpose: grasping the binary search method of ordered table

Teaching Focus: binary search

Teaching Difficulty: binary search

Teaching Content:

Find process of binary lookup

When an ordered table represents a static lookup table, the search function can be implemented using binary lookup.

Determine the range (interval) in which the record is located, and then gradually narrow it down until the record is found or is not found.

Finding realization of Binary lookup

int Search_bin (sstable st,keytype key) {

Low=1;high=st.length;

while (Low<=high) {

Mid= (Low+high)/2;

If EQ (Key,st.elem[mid].key) return mid;

else if LT (Key,st.elem[mid].key) high=mid-1;

else Low=mid +1;

}

return 0;

}//search_bin;

Performance analysis of binary search

Binary find the number of keywords to compare with a given value when looking for success at most

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.