


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 教育在線培訓(xùn)服務(wù)協(xié)議
- 建筑項(xiàng)目設(shè)計(jì)及施工合作協(xié)議
- 大灣區(qū)新興產(chǎn)業(yè)發(fā)展項(xiàng)目合作框架協(xié)議
- 環(huán)??萍柬?xiàng)目研發(fā)與推廣合同
- 總包單位簽訂分包合同
- 買賣手房反擔(dān)保合同
- 承包合同養(yǎng)殖合同
- 私人拖拉機(jī)買賣合同書
- 手房地產(chǎn)轉(zhuǎn)讓居間合同
- 游戲項(xiàng)目開發(fā)授權(quán)及運(yùn)營協(xié)議
- 湘教版三年級美術(shù)下冊教案全冊
- (高清版)DB15∕T 3585-2024 高標(biāo)準(zhǔn)農(nóng)田施工質(zhì)量評定規(guī)程
- 試油(氣)HSE作業(yè)指導(dǎo)書
- 重癥監(jiān)護(hù)-ICU的設(shè)置、管理與常用監(jiān)測技術(shù)
- 法律顧問服務(wù)投標(biāo)方案(完整技術(shù)標(biāo))
- 中醫(yī)藥三方合作協(xié)議書范本
- 2024年《動(dòng)漫藝術(shù)概論》自考復(fù)習(xí)題庫(附答案)
- 2024年職業(yè)技能“大數(shù)據(jù)考試”專業(yè)技術(shù)人員繼續(xù)教育考試題庫與答案
- 慢病報(bào)卡系統(tǒng)使用流程圖
- 2024年遼寧軌道交通職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫含答案
- 小升初數(shù)學(xué)總復(fù)習(xí)專題訓(xùn)練:平行四邊形的面積與梯形的面積
評論
0/150
提交評論