欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    数据结构与程序设计(王丽苹)19search.ppt

    • 资源ID:4980204       资源大小:314.11KB        全文页数:21页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    数据结构与程序设计(王丽苹)19search.ppt

    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,数据结构与程序设计,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 reduce 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 Binary 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 finding 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/2023,数据结构与程序设计,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 looking 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 Binary Search,item=84,first middle last,data0 1 2 3 4 5 6 7 8 9,15 26 38 57 62 78 84 91 108 119,first middle last,5/27/2023,数据结构与程序设计,9,Trace continued,item=84,first,last,middle,first,last middle,item=data middle found=true,5/27/2023,数据结构与程序设计,10,Another Binary Search Trace,item=45,first middle last,data0 1 2 3 4 5 6 7 8 9,15 26 38 57 62 78 84 91 108 119,first middle last,5/27/2023,数据结构与程序设计,11,Trace continued,item=45,first,middle,last,5/27/2023,数据结构与程序设计,12,Trace concludes,item=45,last first,5/27/2023,数据结构与程序设计,13,Binary Search Recognizing Equality P284,Error_code recursive_binary_2(const Ordered_list,5/27/2023,数据结构与程序设计,14,Binary Search Recognizing Equality,Error_code binary_search_2(const Ordered_list,5/27/2023,数据结构与程序设计,15,Binary Search-Main,void main()Key target(5);Ordered_list mylist;for(int i=0;i10;i+)mylist.insert(Record(i,10);coutThe ordered list is:endl;mylist.traverse(print);coutendlThe target is:target.the_key()endl;int bottom=0;int top=mylist.size()-1;int position=-1;coutendlUse recursive_binary_1 Method:endl;if(recursive_binary_1(mylist,target,bottom,top,position)=success)coutGet the target in position:position endl;else coutTarget not present.endl;,5/27/2023,数据结构与程序设计,16,Result,The ordered list is:0 1 2 3 4 5 6 7 8 9The target is:5Use recursive_binary_1 Method:Get the target in position:5,5/27/2023,数据结构与程序设计,17,Binary Search-Main,position=-1;coutendlUse binary_search_1 Method:endl;if(binary_search_1(mylist,target,position)=success)coutGet the target in position:position endl;else coutTarget not present.endl;,5/27/2023,数据结构与程序设计,18,Binary Search-Main,coutendlUse recursive_binary_2 Method:endl;if(recursive_binary_2(mylist,target,bottom,top,position)=success)coutGet the target in position:position endl;else coutTarget not present.endl;position=-1;coutendlUse binary_search_2 Method:endl;if(binary_search_2(mylist,target,position)=success)coutGet the target in position:position endl;else coutTarget not present.endl;cin.get();,5/27/2023,数据结构与程序设计,19,Binary Search-Main,目录BinarySearch下例程,5/27/2023,数据结构与程序设计,20,二分法的效率分析,二分法检索每经过一次比较就将检索范围缩小一半,第i次比较可能比较的元素个数如下表 比较次数 可能比较的元素个数 1 1=20 2 2=21 3 4=22 j 2j-1二分法查找的效率近似为 O(log2n),5/27/2023,数据结构与程序设计,21,Homework,BOOK P285 E1,E2,

    注意事项

    本文(数据结构与程序设计(王丽苹)19search.ppt)为本站会员(牧羊曲112)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开