


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、chapter 8: the disjoint set adt8.1 we assume that unions operated on the roots of the trees containing the arguments. also, in case of tics, the second tree is made a child of the first. arbitrary union and union by height give the same answer (shown as the first tree) for this problem. union by siz
2、e gives the second tree.8.2 in both cases, have nodes 16 and 17 point directly io the root.8.4 claim: a tree of height h has at least 2 nodes. the pn>of is by induction. a tree of height 0 clearly has al least i node, and a tree of height i dearly has al least 2. let t be the tree of height h wit
3、h fewest nodes. thus at the time of 厂 s last union, it must have been a tree of height h i, since otherwise t would have been smaller at that time than it is now and still would have been of height h,which is impossible by assumption of t minimality. since 7s height was updated, it must have been as
4、 a result of a union with another tree of height "-l by (he induction hypothesis, we know that at the time of the union, t had at least 一憲 nodes, as did the tree attached to il, for a total of 2" nodes, proving the claim. thus an 况-node tree has depth at most log jvj.8.5 all answers are 0(
5、af) because in all cases a(m.n) = i.8.6 assuming that the graph has only nine vertices, then (he union/find tree that is formed is shown here. the edge (4.6) does not result in a union because at the time it is examined. 4 and 6 arc already in the same component. the connected components arc 1.2,3.4
6、,6| and8.8 (a) when we perfonn a union, we push onio a slack the two roots and (he old values of their parents. to implement a deuiiion. wc only have to pop the slack and restore the values. tliis strategy works fine in the absence of path compression.(b) if path compression is implemented, the stra
7、tegy described in pari (a) does not work because path compression moves elements out of subtrees. for instance, the sequence union(1.2). union(3.4). union! j.3). find(4). dcunionu.3) will leave 4 in set 1 if path compression is implemented.8.9 we assume that the tree is implemented with pointers ins
8、tead of a simple array. thus find will return a pointer instead of an actual set name. we will keep an array (o map set numbers to their tree nodes. union and find are implemented in the standard manner. to perform remuvetxk first perform a find(x) with path compression. then mark the node containin
9、g x as vacant. create a new one-node tree with x and have it pointed to by the appropriate array entry. the time to perform a remove is the same as the time to perform a find, except that there potentially could be a large number of vacant nodes. to take care of this, after n remove s are performed,
10、 perform a find on every node, with path compression. if a find(x) returns a vacant root, then place x in the root node, and make the old node containing x vacant. the results of exercise 8.11 guarantee that this will take linear time, which can be charged to tlie n remove s. at this point,all vacan
11、t nodes (indeed all nonroot nodes) are children of a root, and vacant nodes can be disposed (if an array of pointers to them has been kept). this also guarantees that (here are never more than in nodes in the forest and preserves the ma(m. n) asymptotic time bound.s. 11 suppose there are u union s a
12、nd f finds. each union costs constant time, for a total of ". a find costs one unit per vertex visited. we charge, as in the text, under the following slightly modified rules:(a) the vertex is a root or child of the root(b) otherwiseessentially,all vertices arc in one rank group. during any fin
13、d, there can be at most two rule (a) charges, for a total of 2f. each vertex can be charged at most once under rule (b) because after path compression it will be a child of the root. the number of vertices that are not roots or children of roots is clearly bounded by independent of the unioning stra
14、tegy, because each union changes exactly one vertex from root to nonroot status, and this bounds the number of type (b) nodes. thus the total rule (b> charges are at most u. adding all charges gives a bound of2/ + 2u,which is linear in the number of operations.8.13 for each vertex r. let the pseu
15、dorank r、be defined as |jog s、j. where sv is the number of descendents (including itself) of v in lhe final tree, after all union s are performed, ignoring-43-path compression.although the pseudorank is not maintained by the algorithm, it is not hard to show that the pscudorank satisfies the same pr
16、operties as the ranks do in union-by-rank. clearly, a vertex with pseudorank r、has at least 2 descendents (by its definition,and the number of vertices of pseudorank r is at most n/2r. tlie union-by-size rule ensures that the parent of a node has twice as many descendents as the node, so the pseudor
17、anks monotonically increase on the path toward the root if there is no path compression. the argument in lemma 8.3 tells us that path compression docs not destroy this property.if we partition the vertices by pseudoranks and assign the charges in the same manner as in the text proof for union-by-ran
18、k. the same steps follow, and the identical bound is obtained.8.14 this is most conveniently implemented without recursion and is faster because, even if full path compression is implemented nonrccursivcly. it requires kvo passes up the tree. this requires only one. wc leave the coding to the reader since comparing (he various union and find strategies is a reasonable programming project. tiic worst-case running time remains (he same because lhe properties of the ranks are unchanged.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 河南机电职业学院《遥感与地理信息系统发展前沿》2023-2024学年第二学期期末试卷
- 重庆信息技术职业学院《信号检测与控制》2023-2024学年第二学期期末试卷
- 网络架构安全运维
- 辽宁工程职业学院《智慧城市工程》2023-2024学年第二学期期末试卷
- 上海中华职业技术学院《工程项目管理软件实验》2023-2024学年第二学期期末试卷
- 广州中医药大学《生态环境保护基础(三)》2023-2024学年第二学期期末试卷
- 甘孜职业学院《桥梁工程(B)》2023-2024学年第二学期期末试卷
- 上海海事大学《职业规划教育课程》2023-2024学年第二学期期末试卷
- 贵州警察学院《教育应用写作》2023-2024学年第二学期期末试卷
- 河北师范大学汇华学院《高频电子线路》2023-2024学年第二学期期末试卷
- Q∕SY 13123-2017 物资仓储技术规范
- 合肥市不动产登记申请审批表-版本
- 防洪度汛检查表
- 手术通知单模板
- 招商合同范本4篇-合同范本
- 《西方音乐史》课件伯辽兹
- 关于互联网金融对商业银行风险影响的实证研究会计学专业
- 十八项电网重大反事故措施
- 液压缸常见故障类型及维修或排除方法
- 河北工业大学本科生体育课程考核管理办法-河北工业大学本科生院
- 数控车床四刀位免抬刀塔装调工艺卡
评论
0/150
提交评论