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