计算机科学外文翻译.docx

上传人:b****5 文档编号:2837561 上传时间:2022-11-15 格式:DOCX 页数:11 大小:74.80KB
下载 相关 举报
计算机科学外文翻译.docx_第1页
第1页 / 共11页
计算机科学外文翻译.docx_第2页
第2页 / 共11页
计算机科学外文翻译.docx_第3页
第3页 / 共11页
计算机科学外文翻译.docx_第4页
第4页 / 共11页
计算机科学外文翻译.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

计算机科学外文翻译.docx

《计算机科学外文翻译.docx》由会员分享,可在线阅读,更多相关《计算机科学外文翻译.docx(11页珍藏版)》请在冰豆网上搜索。

计算机科学外文翻译.docx

计算机科学外文翻译

Binomialheap

Incomputerscience,abinomialheapisaheapsimilartoabinaryheapbutalsosupportsquickmergingoftwoheaps.Thisisachievedbyusingaspecialtreestructure.Itisimportantasanimplementationofthemergeableheapabstractdatatype(alsocalledmeldableheap),whichisapriorityqueuesupportingmergeoperation.

Binomialtree

Abinomialheapisimplementedasacollectionofbinomialtrees(comparewithabinaryheap,whichhasashapeofasinglebinarytree).Abinomialtreeisdefinedrecursively:

∙Abinomialtreeoforder0isasinglenode

∙Abinomialtreeoforderkhasarootnodewhosechildrenarerootsofbinomialtreesofordersk−1,k−2,...,2,1,0(inthisorder).

Binomialtreesoforder0to3:

Eachtreehasarootnodewithsubtreesofalllowerorderedbinomialtrees,whichhavebeenhighlighted.Forexample,theorder3binomialtreeisconnectedtoanorder2,1,and0(highlightedasblue,greenandredrespectively)binomialtree.

Abinomialtreeoforderkhas2knodes,heightk.

Becauseofitsuniquestructure,abinomialtreeoforderkcanbeconstructedfromtwotreesoforderk−1triviallybyattachingoneofthemastheleftmostchildofrootoftheotherone.Thisfeatureiscentraltothemergeoperationofabinomialheap,whichisitsmajoradvantageoverotherconventionalheaps.

Thenamecomesfromtheshape:

abinomialtreeoforder

has

nodesatdepth

.

Structureofabinomialheap

Abinomialheapisimplementedasasetofbinomialtreesthatsatisfythebinomialheapproperties:

∙Eachbinomialtreeinaheapobeystheminimum-heapproperty:

thekeyofanodeisgreaterthanorequaltothekeyofitsparent.

∙Therecanonlybeeitheroneorzerobinomialtreesforeachorder,includingzeroorder.

Thefirstpropertyensuresthattherootofeachbinomialtreecontainsthesmallestkeyinthetree,whichappliestotheentireheap.

Thesecondpropertyimpliesthatabinomialheapwithnnodesconsistsofatmostlogn+1binomialtrees.Infact,thenumberandordersofthesetreesareuniquelydeterminedbythenumberofnodesn:

eachbinomialtreecorrespondstoonedigitinthebinaryrepresentationofnumbern.Forexamplenumber13is1101inbinary,

andthusabinomialheapwith13nodeswillconsistofthreebinomialtreesoforders3,2,and0(seefigurebelow).

Exampleofabinomialheapcontaining13nodeswithdistinctkeys.

Theheapconsistsofthreebinomialtreeswithorders0,2,and3.

Implementation

Becausenooperationrequiresrandomaccesstotherootnodesofthebinomialtrees,therootsofthebinomialtreescanbestoredinalinkedlist,orderedbyincreasingorderofthetree.

Merge

Asmentionedabove,thesimplestandmostimportantoperationisthemergingoftwobinomialtreesofthesameorderwithintwobinomialheaps.Duetothestructureofbinomialtrees,theycanbemergedtrivially.Astheirrootnodeisthesmallestelementwithinthetree,bycomparingthetwokeys,thesmallerofthemistheminimumkey,andbecomesthenewrootnode.Thentheothertreebecomeasubtreeofthecombinedtree.Thisoperationisbasictothecompletemergingoftwobinomialheaps.

functionmergeTree(p,q)

ifp.root.key<=q.root.key

returnp.addSubTree(q)

else

returnq.addSubTree(p)

Tomergetwobinomialtreesofthesameorder,firstcomparetherootkey.Since7>3,theblacktreeontheleft(withrootnode7)isattachedtothegreytreeontheright(withrootnode3)asasubtree.Theresultisatreeoforder3.

Theoperationofmergingtwoheapsisperhapsthemostinterestingandcanbeusedasasubroutineinmostotheroperations.Thelistsofrootsofbothheapsaretraversedsimultaneously,similarlyasinthemergealgorithm

Ifonlyoneoftheheapscontainsatreeoforderj,thistreeismovedtothemergedheap.Ifbothheapscontainatreeoforderj,thetwotreesaremergedtoonetreeoforderj+1sothattheminimum-heappropertyissatisfied.Notethatitmaylaterbenecessarytomergethistreewithsomeothertreeoforderj+1presentinoneoftheheaps.Inthecourseofthealgorithm,weneedtoexamineatmostthreetreesofanyorder(twofromthetwoheapswemergeandonecomposedoftwosmallertrees).

Becauseeachbinomialtreeinabinomialheapcorrespondstoabitinthebinaryrepresentationofitssize,thereisananalogybetweenthemergingoftwoheapsandthebinaryadditionofthesizesofthetwoheaps,fromright-to-left.Wheneveracarryoccursduringaddition,thiscorrespondstoamergingoftwobinomialtreesduringthemerge.

EachtreehasorderatmostlognandthereforetherunningtimeisO(logn).

functionmerge(p,q)

whilenot(p.end()andq.end())

tree=mergeTree(p.currentTree(),q.currentTree())

ifnotheap.currentTree().empty()

tree=mergeTree(tree,heap.currentTree())

heap.

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高中教育 > 高考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1