Heaps(PriorityQueues)Aheapisadatastructurewhich.ppt


文档分类:医学/心理学 | 页数:约17页 举报非法文档有奖
1/17
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/17
文档列表 文档介绍
Heaps(PriorityQueues)Aheapisadatastructurewhichsupportsefficientimplementationofthreeoperations:insert,findMin,anddeleteMin.(Suchaheapisamin-heap,tobemoreprecise.)Twoobviousimplementationsarebasedonanarray(assumingthesizenisknown):insertfindMindeleteMinSortedarrayO(n) O(1)O(1)(fromlarge(tomove(findatend) (deletetheend)tosmall)elements) LinkedlistO(1)O(1)O(n) (append)(apointertoMin)(resetMinpointer)Asimplerbutrelatedproblem:Findthesmallestandthesecondsmallestelementsinanarray(ofsizen):Astraightforwardmethod:Findthesmallestusingn–1comparisons;swapittotheendofthearray,findthenextsmallestinn–2comparisons,foratotalof2n–“saves”parisons:(1)Dividethearrayintotwohalves,findthesmallestelementsofeachhalf,callthemmin1andmin2,respectively;(paremin1andmin2,tofindthesmallest;(3)hesecondsmallest;(n–1)+(n/2–1)=(3n/2–:min1min2minFirsthalfofarraySecondhalfofarrayInthefigure,alinkconnectsasmallerelementtoalargeronegoingdownward;forexample,minmin1andminmin2,andmin1eachelementinthefirsthalfofthearray,-heaps:pletebinarytreeifthetreeisfullateachlevelexceptpossiblyatthemaximumlevel(depth),wherethetreeisfullatlevelimeansthereare2inodesatthatlevel(recalltherootisatlevel0);andatthetree’smaximumlevelh,,then2hn2h+1–,hlgn<(h+1).Inparticular,h=O(lgn).Abinarytreesatisfiesthe(min-)heap-orderpropertyifthevalueateachislessthanorequaltothevalueateachofthechildnodes(ifexist).Abinarymin-pletebinarytreethatalsosatisfiestheheap-;also,-heapTwobasicoperationsonbinarymin-heaps:Supposethevalu

Heaps(PriorityQueues)Aheapisadatastructurewhich 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数17
  • 收藏数0 收藏
  • 顶次数0
  • 上传人1387230****
  • 文件大小96 KB
  • 时间2020-08-10