版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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届初三一模物理试题(含答案)
- 2025年数字货币跨境结算法律场景报告
- 医院消毒供应监测基本数据集解读与实践
- 民兵护路基本知识培训课件
- 老年肌少症的预防及护理
- 武汉大学保密管理办法
- 技术调研实施管理办法
- 网络空间安全概论 实验6 网络监听实验样例1
- T/CECS 10055-2019绿色建材评价集成墙面
评论
0/150
提交评论