版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、CHAPTER 10SEARCH STRUCTURES1 Optimal Binary Search Trees The best for static searching (without insertion and deletion)whileifdodoifwhileifdowhilewhiledoifdowhileif Which one is the best? It depends on how often we need to search each of the identifiers.An external (or failure) nodeAn internal nodeE
2、xtendedBinaryTrees External path length := whilevoidifdoforE = 2 + 2 + 2 + 3 + 4 + 4 = 17 Internal path length := I = 0 + 1 + 1 + 2 + 3 = 7E = I + 2nHW: p.480 #1That means thatwhen I gets larger,E gets larger as well. Worst case ( ? ) I = ? Best case ( ? ) I = ?skewedcomplete1 Optimal Binary Search
3、Trees Given n identifiers a1 a2 an, and the probability of searching for each ai is pi , then for the successful searches, the cost of any binary search tree is Notice that unsuccessful searches terminate at failure nodes.E0 a1 E1 a2 En1 an En where and for all identifiers in some Ei, the search ter
4、minates at the same failure node fi . If qi is the probability that the identifier we are searching for is in Ei , then the cost for the unsuccessful searches is 1 Optimal Binary Search TreesThe total cost of a binary search treewhere An optimal binary search tree for a set of identifiers is one tha
5、t minimizes the cost over all possible binary search trees for this identifier set.Note: Tp for computing the cost of a binary search tree is O( n ). But there are O( 4n / n3/2 ) distinct binary search trees with n identifiers!1 Optimal Binary Search TreesPlease read Example 10.1 on p.474An algorith
6、m with Tp = O( n2 ) Can you believe it?Ti j := OBST for ai+1 , , aj ( i j.ri j := root of Ti j ( ri i = 0 )wi j := weight of Ti j = ( wi i = qi )Ei ai+1 Ej1 aj Ejqi pi+1 qj1 pj qjwi jT0n with root r0n,weight w0n, andcost c0n .1 Optimal Binary Search TreesakLai+1ak1Rak+1ajTi j1 Optimal Binary Search
7、TreesThe total cost of a binary search treeci j = ?pk + cost( L ) + cost( R )+ weight( L ) + weight( R )= pk + ci, k1 + ck j + wi, k1 + wk j = wi j + ci, k1 + ck j Ti j is optimal ri j = k is such that Starting from Ti i = and ci i = 0, we can obtain Ton and c0n .1 Optimal Binary Search TreesExample
8、Let (a1, a2, a3, a4) = ( do, for, void, while ). Let ( p1, p2, p3, p4) = (3, 3, 1, 1) /16 and ( q0, q1, q2, q3, q4) = (2, 3, 1, 1, 1) /16 w00 = 2c00 = 0r00 = 0w11 = 3c11 = 0r11 = 0w22 = 1c22 = 0r22 = 0w33 = 1c33 = 0r33 = 0w44= 1c44 = 0r44 = 0w01 = 8c01 = 8r01 = 1w12 = 7c12 = 7r12 = 2w23 = 3c23 = 3r23 = 3w34 = 3c34 = 3r34 = 4w02 = 12c02 = 19r02 = 1w13 = 9c13 = 12r13 = 2w24 = 5c24 = 8r24 = 3w03 = 14c03 = 25r03 = 2w14 = 11c14 = 19r14 = 2w04 = 16c04 = 32r04 = 2fordovoidwhilej i =1j i =2j i =3j i =4T Wij = O( n + 1 j + i )Trij = O( j i )Let
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年宁夏建设职业技术学院高职单招职业适应性考试备考试题带答案解析
- 2026年重庆工程学院高职单招职业适应性测试参考题库带答案解析
- 2026年定西师范高等专科学校单招综合素质考试模拟试题附答案详解
- 2026 年高职艺术学类(舞蹈表演)试题及答案
- 年中考化学一轮复习-微专题质量守恒定律的应用之定量计算课件
- 农村盖房子协议书
- 半导体分立器件和集成电路装调工成果考核试卷含答案
- 未来五年鹰爪虾企业县域市场拓展与下沉战略分析研究报告
- 未来五年硝酸及硝酸钾镁企业ESG实践与创新战略分析研究报告
- 未来五年水土流失防治服务企业数字化转型与智慧升级战略分析研究报告
- 昆山钞票纸业有限公司2026年度招聘备考题库附答案详解
- GB/T 46793.1-2025突发事件应急预案编制导则第1部分:通则
- 2025年中国工艺美术馆面向社会招聘工作人员2人笔试历年典型考题及考点剖析附带答案详解
- 肿瘤学课件:女性生殖系统肿瘤(中文版)
- 焊缝的图示法
- 化工厂新员工安全培训教材DOC
- 2020年云南省中考英语试卷真题及答案详解(含作文范文)
- GB/T 2951.11-2008电缆和光缆绝缘和护套材料通用试验方法第11部分:通用试验方法-厚度和外形尺寸测量-机械性能试验
- GB/T 23636-2017铅酸蓄电池用极板
- GB/T 12642-2013工业机器人性能规范及其试验方法
- GB 19272-2003健身器材室外健身器材的安全通用要求
评论
0/150
提交评论