数据结构与程序设计(王丽苹)19search.ppt
《数据结构与程序设计(王丽苹)19search.ppt》由会员分享,可在线阅读,更多相关《数据结构与程序设计(王丽苹)19search.ppt(21页珍藏版)》请在三一办公上搜索。
1、5/27/2023,数据结构与程序设计,1,数据结构与程序设计(19),王丽苹,5/27/2023,数据结构与程序设计,2,Binary SearchThe Forgetful Version of Binary Search,Forget the possibility that the Key target might be found quickly and continue,whether target has been found or not,to subdivide the list until what remains has length 1.,5/27/2023,数据结构与
2、程序设计,3,Binary SearchThe Forgetful Version of Binary Search,Idea:In searching an ordered list,first compare the target to the key in the center of the list.If it is smaller,restrict the search to the left half;otherwise restrict the search to the right half,and repeat.In this way,at each step we redu
3、ce the length of the list to be searched by half.Keep two indices,top and bottom,that will bracket the part of the list still to be searched.The target key,provided it is present,will be found between the indices bottom and top,inclusive.,5/27/2023,数据结构与程序设计,4,Binary SearchThe Forgetful Version of B
4、inary Search,Initialization:Set bottom=0;top=the_list.size()1;Compare target with the Record at the midpoint,mid=(bottom+top)/2;Change the appropriate index top or bottom to restrict the search to the appropriate half of the list.Loop terminates when top=bottom,if it has not terminated earlier by fi
5、nding the target.Make progress toward termination by ensuring that the number of items remaining to be searched,top bottom+1,strictly decreases at each iteration of the process.,5/27/2023,数据结构与程序设计,5,The Forgetful Version of Binary Search P282,Error_code recursive_binary_1(const Ordered_list,5/27/20
6、23,数据结构与程序设计,6,The Forgetful Version of Binary Search P283,Error_code binary_search_1(const Ordered_list,5/27/2023,数据结构与程序设计,7,Binary Search(Recognizing Equality),Examines the element in the middle of the array.Is it the sought item?If so,stop searching.Is the middle element too small?Then start loo
7、king in second half of array.Is the middle element too large?Then begin looking in first half of the array.Repeat the process in the half of the data that should be examined next.Stop when item is found,or when there is nowhere else to look and item has not been found.,5/27/2023,数据结构与程序设计,8,Trace of
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 程序设计 王丽苹 19 search
链接地址:https://www.31ppt.com/p-4980204.html