计算机科学外文翻译Word格式文档下载.docx
- 文档编号:15748625
- 上传时间:2022-11-15
- 格式:DOCX
- 页数:11
- 大小:74.80KB
计算机科学外文翻译Word格式文档下载.docx
《计算机科学外文翻译Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《计算机科学外文翻译Word格式文档下载.docx(11页珍藏版)》请在冰豆网上搜索。
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.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机科学 外文 翻译