版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 多媒体课件制作教案
- 第六章氧族元素环境保护教案(人教版)
- 研发质量管理办法
- 生态养殖山坡地租赁合同
- 六年级计算机上册教案
- 农业设施地面施工合同
- 农业发展资金扶持办法
- 绿色建筑房产交易合同样本
- 拆除消防班组施工合同
- 工业区护栏施工合同模板
- CQC 11-463901-2011 额定电压300∕500V生活设施加热和防结冰用加热电缆安全认证规则
- 全球及中国测井仪器行业市场现状供需分析及市场深度研究发展前景及规划可行性分析研究报告(2024-2030)
- QBT 1950-2024 家具表面漆膜耐盐浴测定法(正式版)
- 2024年1月甘肃省公安厅招考聘用辅警109人笔试历年典型考题及考点研判与答案解析
- 中国历史地理概况 知到智慧树网课答案
- DZ∕T 0222-2006 地质灾害防治工程监理规范(正式版)
- DZ∕T 0212.3-2020 矿产地质勘查规范 盐类 第3部分:古代固体盐类(正式版)
- 2024广西专业技术人员继续教育公需科目参考答案
- 工程变更通知单ECN模板-20220213
- 《DB32T 4226-2022连续肾脏替代治疗装置临床使用安全管理与质量控制规范》
- Q GDW 10115-2022 110kV~1000kV架空输电线路施工及验收规范
评论
0/150
提交评论