版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年省属国企公开招聘备考题库完整答案详解
- 2025年杭州之江湾股权投资基金管理有限公司招聘备考题库及一套答案详解
- 2025年景洪市嘎洒强村管理有限公司人员招聘备考题库及参考答案详解1套
- 2025年鄂伦春自治旗人民医院消防人员招聘备考题库附答案详解
- 2025年鄂尔多斯市胜丰种业有限公司科研助理招聘备考题库及完整答案详解1套
- 2026年天津高级中学-骨干教师及青年教师招聘备考题库及参考答案详解一套
- 2025年郴州市第三人民医院员工招聘备考题库及完整答案详解1套
- 2025年中国瑞林工程技术股份有限公司杭州分公司(国企上市公司)招聘结构设计师备考题库带答案详解
- 2025年江门市江海区银信资产管理有限公司招聘备考题库及参考答案详解一套
- 沧州市中心医院2026年度高层次人才选聘170人备考题库及1套参考答案详解
- sw水箱施工方案
- 2023-2024学年广东省广州市海珠区八年级(上)期末地理试题及答案
- 旅游策划理论及实务第1章旅游策划导论
- 中华人民共和国治安管理处罚法2025修订版测试题及答案
- 产品生命周期管理(PLM)方案
- istqb考试题目及答案
- 2025年嫩江市招聘农垦社区工作者(88人)笔试备考试题附答案详解(a卷)
- 展厅空间设计案例
- 企业降本增效课件
- 中医护理技术提升与临床应用
- 兖矿新疆煤化工有限公司年产60万吨醇氨联产项目环评报告
评论
0/150
提交评论