Share to: share facebook share twitter share wa share telegram print page

Pairing heap

A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance, introduced by Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan in 1986.[1] Pairing heaps are heap-ordered multiway tree structures, and can be considered simplified Fibonacci heaps. They are considered a "robust choice" for implementing such algorithms as Prim's MST algorithm,[2] and support the following operations (assuming a min-heap):

  • find-min: simply return the top element of the heap.
  • meld: compare the two root elements, the smaller remains the root of the result, the larger element and its subtree is appended as a child of this root.
  • insert: create a new heap for the inserted element and meld into the original heap.
  • decrease-key (optional): remove the subtree rooted at the key to be decreased, replace the key with a smaller key, then meld the result back into the heap.
  • delete-min: remove the root and do repeated melds of its subtrees until one tree remains. Various merging strategies are employed.

The analysis of pairing heaps' time complexity was initially inspired by that of splay trees.[1] The amortized time per delete-min is O(log n), and the operations find-min, meld, and insert run in O(1) time.[3]

When a decrease-key operation is added as well, determining the precise asymptotic running time of pairing heaps has turned out to be difficult. Initially, the time complexity of this operation was conjectured on empirical grounds to be O(1),[4] but Fredman proved that the amortized time per decrease-key is at least for some sequences of operations.[5] Using a different amortization argument, Pettie then proved that insert, meld, and decrease-key all run in amortized time, which is .[6] Elmasry later introduced elaborations of pairing heaps (lazy, consolidate) for which decrease-key runs in amortized time and other operations have optimal amortized bounds,[7][8] but no tight bound is known for the original data structure.[3][6]

Although the asymptotic performance of pairing heaps is worse than other priority queue algorithms such as Fibonacci heaps, which perform decrease-key in amortized time, the performance in practice is excellent. Jones[9] and Larkin, Sen, and Tarjan[10] conducted experiments on pairing heaps and other heap data structures. They concluded that d-ary heaps such as binary heaps are faster than all other heap implementations when the decrease-key operation is not needed (and hence there is no need to externally track the location of nodes in the heap), but that when decrease-key is needed pairing heaps are often faster than d-ary heaps and almost always faster than other pointer-based heaps, including data structures like Fibonacci heaps that are theoretically more efficient. Chen et al.[11] examined priority queues specifically for use with Dijkstra's algorithm and concluded that in normal cases using a d-ary heap without decrease-key (instead duplicating nodes on the heap and ignoring redundant instances) resulted in better performance, despite the inferior theoretical performance guarantees.

Structure

A pairing heap is either an empty heap, or a pairing tree consisting of a root element and a possibly empty list of pairing trees. The heap ordering property requires that parent of any node is no greater than the node itself. The following description assumes a purely functional heap that does not support the decrease-key operation.

type PairingTree[Elem] = Heap(elem: Elem, subheaps: List[PairingTree[Elem]])
type PairingHeap[Elem] = Empty | PairingTree[Elem]

A pointer-based implementation for RAM machines, supporting decrease-key, can be achieved using three pointers per node, by representing the children of a node by a doubly-linked list: a pointer to the node's first child, one to its next sibling, and one to its previous sibling (or, for the leftmost sibling, to its parent). It can also be viewed as a variant of a Left-child right-sibling binary tree with an additional pointer to a node's parent (which represents its previous sibling or actual parent for the leftmost sibling). Alternatively, the previous-pointer can be omitted by letting the last child point back to the parent, if a single boolean flag is added to indicate "end of list". This achieves a more compact structure at the expense of a constant overhead factor per operation.[1]

Operations

Meld

Melding with an empty heap returns the other heap, otherwise a new heap is returned that has the minimum of the two root elements as its root element and just adds the heap with the larger root to the list of subheaps:

function meld(heap1, heap2: PairingHeap[Elem]) -> PairingHeap[Elem]
    if heap1 is Empty
        return heap2
    elsif heap2 is Empty
        return heap1
    elsif heap1.elem < heap2.elem
        return Heap(heap1.elem, heap2 :: heap1.subheaps)
    else
        return Heap(heap2.elem, heap1 :: heap2.subheaps)

Insert

The easiest way to insert an element into a heap is to meld the heap with a new heap containing just this element and an empty list of subheaps:

function insert(elem: Elem, heap: PairingHeap[Elem]) -> PairingHeap[Elem]
    return meld(Heap(elem, []), heap)

Find-min

The function find-min simply returns the root element of the heap:

function find-min(heap: PairingHeap[Elem]) -> Elem
    if heap is Empty
        error
    else
        return heap.elem

Delete-min

The only non-trivial fundamental operation is the deletion of the minimum element from the heap. This requires performing repeated melds of its children until only one tree remains. The standard strategy first melds the subheaps in pairs (this is the step that gave this data structure its name) from left to right and then melds the resulting list of heaps from right to left:

function delete-min(heap: PairingHeap[Elem]) -> PairingHeap[Elem]
    if heap is Empty
        error
    else
        return merge-pairs(heap.subheaps)

This uses the auxiliary function merge-pairs:

function merge-pairs(list: List[PairingTree[Elem]]) -> PairingHeap[Elem]
    if length(list) == 0
        return Empty
    elsif length(list) == 1
        return list[0]
    else
        return meld(meld(list[0], list[1]), merge-pairs(list[2..]))

That this does indeed implement the described two-pass left-to-right then right-to-left merging strategy can be seen from this reduction:

   merge-pairs([H1, H2, H3, H4, H5, H6, H7])
=> meld(meld(H1, H2), merge-pairs([H3, H4, H5, H6, H7]))
     # meld H1 and H2 to H12, then the rest of the list
=> meld(H12, meld(meld(H3, H4), merge-pairs([H5, H6, H7])))
     # meld H3 and H4 to H34, then the rest of the list
=> meld(H12, meld(H34, meld(meld(H5, H6), merge-pairs([H7]))))
     # meld H5 and H6 to H56, then the rest of the list
=> meld(H12, meld(H34, meld(H56, H7)))
     # switch direction, meld the last two resulting heaps, giving H567
=> meld(H12, meld(H34, H567))
     # meld the last two resulting heaps, giving H34567
=> meld(H12, H34567) 
     # finally, meld the first pair with the result of merging the rest
=> H1234567

Summary of running times

Here are time complexities[12] of various heap data structures. Function names assume a min-heap. For the meaning of "O(f)" and "Θ(f)" see Big O notation.

Operation find-min delete-min insert decrease-key meld
Binary[12] Θ(1) Θ(log n) O(log n) O(log n) Θ(n)
Leftist Θ(1) Θ(log n) Θ(log n) O(log n) Θ(log n)
Binomial[12][13] Θ(1) Θ(log n) Θ(1)[a] Θ(log n) O(log n)
Skew binomial[14] Θ(1) Θ(log n) Θ(1) Θ(log n) O(log n)[b]
Pairing[3] Θ(1) O(log n)[a] Θ(1) o(log n)[a][c] Θ(1)
Rank-pairing[17] Θ(1) O(log n)[a] Θ(1) Θ(1)[a] Θ(1)
Fibonacci[12][18] Θ(1) O(log n)[a] Θ(1) Θ(1)[a] Θ(1)
Strict Fibonacci[19] Θ(1) O(log n) Θ(1) Θ(1) Θ(1)
Brodal[20][d] Θ(1) O(log n) Θ(1) Θ(1) Θ(1)
2–3 heap[22] Θ(1) O(log n)[a] Θ(1)[a] Θ(1) O(log n)
  1. ^ a b c d e f g h i Amortized time.
  2. ^ Brodal and Okasaki describe a technique to reduce the worst-case complexity of meld to Θ(1); this technique applies to any heap datastructure that has insert in Θ(1) and find-min, delete-min, meld in O(log n).
  3. ^ Lower bound of [15] upper bound of [16]
  4. ^ Brodal and Okasaki later describe a persistent variant with the same bounds except for decrease-key, which is not supported. Heaps with n elements can be constructed bottom-up in O(n).[21]

References

  1. ^ a b c Fredman, Michael L.; Sedgewick, Robert; Sleator, Daniel D.; Tarjan, Robert E. (1986). "The pairing heap: a new form of self-adjusting heap" (PDF). Algorithmica. 1 (1–4): 111–129. doi:10.1007/BF01840439. S2CID 23664143.
  2. ^ Mehlhorn, Kurt; Sanders, Peter (2008). Algorithms and Data Structures: The Basic Toolbox (PDF). Springer. p. 231.
  3. ^ a b c Iacono, John (2000), "Improved upper bounds for pairing heaps", Proc. 7th Scandinavian Workshop on Algorithm Theory (PDF), Lecture Notes in Computer Science, vol. 1851, Springer-Verlag, pp. 63–77, arXiv:1110.4428, CiteSeerX 10.1.1.748.7812, doi:10.1007/3-540-44985-X_5, ISBN 3-540-67690-2
  4. ^ Stasko, John T.; Vitter, Jeffrey S. (1987), "Pairing heaps: experiments and analysis" (PDF), Communications of the ACM, 30 (3): 234–249, CiteSeerX 10.1.1.106.2988, doi:10.1145/214748.214759, S2CID 17811811
  5. ^ Fredman, Michael L. (1999). "On the efficiency of pairing heaps and related data structures" (PDF). Journal of the ACM. 46 (4): 473–501. doi:10.1145/320211.320214. S2CID 16115266. Archived from the original (PDF) on 2011-07-21. Retrieved 2011-05-03.
  6. ^ a b Pettie, Seth (2005), "Towards a final analysis of pairing heaps" (PDF), Proc. 46th Annual IEEE Symposium on Foundations of Computer Science (PDF), pp. 174–183, doi:10.1109/SFCS.2005.75, ISBN 0-7695-2468-0, S2CID 2717102
  7. ^ Elmasry, Amr (2009), "Pairing heaps with O(log log n) decrease cost" (PDF), Proc. 20th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 471–476, CiteSeerX 10.1.1.502.6706, doi:10.1137/1.9781611973068.52
  8. ^ Elmasry, Amr (November 2017). "Toward Optimal Self-Adjusting Heaps". ACM Transactions on Algorithms. 13 (4): 1–14. doi:10.1145/3147138. S2CID 1182235.
  9. ^ Jones, Douglas W. (1986). "An empirical comparison of priority-queue and event-set implementations". Communications of the ACM. 29 (4): 300–311. CiteSeerX 10.1.1.117.9380. doi:10.1145/5684.5686. S2CID 43650389.
  10. ^ Larkin, Daniel H.; Sen, Siddhartha; Tarjan, Robert E. (2014), "A back-to-basics empirical study of priority queues", Proceedings of the 16th Workshop on Algorithm Engineering and Experiments, pp. 61–72, arXiv:1403.0252, doi:10.1137/1.9781611973198.7, ISBN 978-1-61197-319-8, S2CID 15216766
  11. ^ Chen, Mo; Chowdhury, Rezaul Alam; Ramachandran, Vijaya; Roche, David Lan; Tong, Lingling (12 October 2007). Priority Queues and Dijkstra's Algorithm (PDF) (Technical report). University of Texas. TR-07-54.{{cite tech report}}: CS1 maint: date and year (link)
  12. ^ a b c d Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L. (1990). Introduction to Algorithms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8.
  13. ^ "Binomial Heap | Brilliant Math & Science Wiki". brilliant.org. Retrieved 2019-09-30.
  14. ^ Brodal, Gerth Stølting; Okasaki, Chris (November 1996), "Optimal purely functional priority queues", Journal of Functional Programming, 6 (6): 839–857, doi:10.1017/s095679680000201x
  15. ^ Fredman, Michael Lawrence (July 1999). "On the Efficiency of Pairing Heaps and Related Data Structures" (PDF). Journal of the Association for Computing Machinery. 46 (4): 473–501. doi:10.1145/320211.320214.
  16. ^ Pettie, Seth (2005). Towards a Final Analysis of Pairing Heaps (PDF). FOCS '05 Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science. pp. 174–183. CiteSeerX 10.1.1.549.471. doi:10.1109/SFCS.2005.75. ISBN 0-7695-2468-0.
  17. ^ Haeupler, Bernhard; Sen, Siddhartha; Tarjan, Robert E. (November 2011). "Rank-pairing heaps" (PDF). SIAM J. Computing. 40 (6): 1463–1485. doi:10.1137/100785351.
  18. ^ Fredman, Michael Lawrence; Tarjan, Robert E. (July 1987). "Fibonacci heaps and their uses in improved network optimization algorithms" (PDF). Journal of the Association for Computing Machinery. 34 (3): 596–615. CiteSeerX 10.1.1.309.8927. doi:10.1145/28869.28874.
  19. ^ Brodal, Gerth Stølting; Lagogiannis, George; Tarjan, Robert E. (2012). Strict Fibonacci heaps (PDF). Proceedings of the 44th symposium on Theory of Computing - STOC '12. pp. 1177–1184. CiteSeerX 10.1.1.233.1740. doi:10.1145/2213977.2214082. ISBN 978-1-4503-1245-5.
  20. ^ Brodal, Gerth S. (1996), "Worst-Case Efficient Priority Queues" (PDF), Proc. 7th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 52–58
  21. ^ Goodrich, Michael T.; Tamassia, Roberto (2004). "7.3.6. Bottom-Up Heap Construction". Data Structures and Algorithms in Java (3rd ed.). pp. 338–341. ISBN 0-471-46983-1.
  22. ^ Takaoka, Tadao (1999), Theory of 2–3 Heaps (PDF), p. 12

Read other articles:

JR東海キヤ97系気動車JR東日本キヤE195系気動車 JR東海キヤ97系R3編成・定尺レール運搬用(2008年6月・袋井駅)基本情報運用者 東海旅客鉄道・東日本旅客鉄道製造所 日本車輌製造製造年 キヤ97系:2007年 - キヤE195系:2017年 -主要諸元編成 キヤ97系R1-4編成:2両固定(2M)R101編成:最大13両(8M5T)キヤE195系ST-1 - 17編成:2両固定(2M)LT-1 - 4編成:最大11両(8M3T)軌間 1,067 mm(狭軌)最高運

Australian politician The HonourableMartin Hamilton-SmithMinister for Investment and TradeIn office27 May 2014 – 17 January 2018PremierJay WeatherillPreceded bySusan Close (as Minister for Manufacturing, Innovation and Trade)Minister for Small BusinessIn office19 January 2016 – 17 January 2018PremierJay WeatherillPreceded byTom KoutsantonisMinister for Defence and Space IndustriesIn office27 May 2014 – 17 January 2018PremierJay WeatherillPreceded byJack SnellingM…

جزء من سلسلة حولالتمييز أشكال عامة عمر طائفة طبقة لون إعاقة نمط وراثي شعر طول لغة مظهر سمات عقلية عرق / أثنية / جنسية رتبة دين جنس توجه جنسي حجم أنواع أشكال محددة   اجتماعية رهاب اللاجنسية وصمة عار الإيدز سلطة البالغين اضطهاد المصابين بالبرص معاداة التشرد معاداة المثق…

تحتاج هذه المقالة إلى الاستشهاد بمصادر إضافية لتحسين وثوقيتها. فضلاً ساهم في تطوير هذه المقالة بإضافة استشهادات من مصادر موثوقة. من الممكن التشكيك بالمعلومات غير المنسوبة إلى مصدر وإزالتها. (مارس 2010) علاجات مرض السرطان معلومات عامة الاختصاص علم الأورام  من أنواع علاج 

Film Titel Der unendliche Weg Produktionsland Deutsches Reich Originalsprache Deutsch Erscheinungsjahr 1943 Länge 96 Minuten Altersfreigabe FSK 6 Stab Regie Hans Schweikart Drehbuch Walter von MoloErnst von Salomon Produktion Gerhard Staab (Herstellungsgruppe) Musik Oskar Wagner Kamera Franz Koch Schnitt Ludolf Grisebach Besetzung Eugen Klöpfer: Friedrich List, Nationalökonom Eva Immermann: Mila List, seine Tochter Hedwig Wangel: Susan Harper, genannt Tante Sannah Alice Treff: Helen Harp…

NossisNossis (patung dada marmer karya Francesco Jerace)Nama asliΝοσσίςLahirEpizephyrian LocrisMeninggalEpizephyrian LocrisMakamTidak diketahuiPekerjaanPenyairBahasaYunaniKewarganegaraanOrang LocrianTahun aktifca. 300 SMAnakMelinno (diyakini) Nossis (Yunani: Νοσσίς) adalah seorang penyair Yunani Helenistik asal Epizephyrian Locris di selatan Italia.[1] Ia tampaknya aktif pada awal abad ketiga SM.[2] Ia biasanya menulis epigram untuk dedikasi agama dan …

In the run up to the 1989 Spanish general election, various organisations carried out opinion polling to gauge voting intention in Spain during the term of the 3rd Cortes Generales. Results of such polls are displayed in this article. The date range for these opinion polls is from the previous general election, held on 22 June 1986, to the day the next election was held, on 29 October 1989. Voting intention estimates refer mainly to a hypothetical Congress of Deputies election. Polls are listed …

ERC 90 SAGAIE Французький ERC 90 Fl Lynx на параді у ПарижіТип бойова розвідувальна машинаПоходження ФранціяІсторія використанняНа озброєнні з 1982Оператори див. ОператориВійни див. ВійниІсторія виробництваРозробник PanhardРозроблено 1975Виготовлення 1979Варіанти див. ВаріантиХаракте…

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Oktober 2022. Ismiyati[1] adalah seorang penulis cerpen wanita yang terkenal pada dasawarsa 1960-an. Melalui karyanya Sura Dira Jayadiningrat, Lebur déning Pangastuti, Ismiyati memenangkan lomba penulisan cerpen majalah Jaya Baya nomor 19 Th. XVII, 29 Desember…

This article is about the 1st century Christian believer. For the Athenian comic poet, see Archippus (poet). For the 2nd century BCE Greek general, see Archippus of Achaea. ArchippusMartyrBornpossibly at Colossae or Laodicea(modern-day Honaz or Denizli, Turkey)Diedc. 1st centuryFeast19 February (Eastern Orthodox Church)20 March (Roman Catholic Church) Archippus (/ɑːrˈkɪpəs/; Ancient Greek: Ἄρχιππος, master of the horse) was an early Christian believer mentioned briefly in the New T…

Species of moth Catocala formosana Scientific classification Domain: Eukaryota Kingdom: Animalia Phylum: Arthropoda Class: Insecta Order: Lepidoptera Superfamily: Noctuoidea Family: Erebidae Genus: Catocala Species: C. formosana Binomial name Catocala formosanaOkano, 1958 Catocala formosana is a moth in the family Erebidae first described by Okano in 1958.[1] It is found in Taiwan.[2] References Wikimedia Commons has media related to Catocala formosana. Wikispecies has infor…

1994年のフェアチャイルド空軍基地でのB-52機の墜落事故は、運用限界を超える機体の操縦が原因であった。墜落直前を捉えたこの写真で、機体は復元不能な傾斜を見せている。この事故は、乗務員の職務分担などリソース・マネジメントを教育するケース・スタディの検討事例として、軍民双方で利用されている。 滑走路上で航空機同士が衝突した リナーテ空港事故では…

MarEliya XCatholicos-Patriarch of the EastChurchChurch of the EastInstalled1700Term ended1722PredecessorEliya IXSuccessorEliya XIPersonal detailsDied14 December 1722ResidenceRabban Hormizd Monastery The ancient Rabban Hormizd Monastery, former residence of the Patriarchs of the Church of the East Eliya X (Syriac: ܐܠܝܐ / Elīyā, d. 14 December 1722) was Patriarch of the Church of the East from 1700 to 1722, with residence in Rabban Hormizd Monastery, near Alqosh, in modern Iraq.[1] D…

Receptor to which cortisol and other glucocorticoids bind NR3C1Available structuresPDBOrtholog search: PDBe RCSB List of PDB id codes1M2Z, 1NHZ, 1P93, 3BQD, 3CLD, 3E7C, 3H52, 3K22, 3K23, 4CSJ, 4HN5, 4HN6, 4LSJ, 4MDD, 4P6W, 4P6X, 5CBY, 5CBX, 4UDC, 4UDD, 5CBZ, 5CC1, 5EMQ, 5EMC, 5EMPIdentifiersAliasesNR3C1, GCCR, GCR, GCRST, GR, GRL, nuclear receptor subfamily 3 group C member 1, Glucocorticoid ReceptorExternal IDsOMIM: 138040 MGI: 95824 HomoloGene: 30960 GeneCards: NR3C1 Gene location (Human)Chr.C…

Grande Prêmio de Abu Dhabi de Fórmula 1 de 2014 Grande Prêmio de Abu Dhabi de 2014. Detalhes da corrida Data 23 de novembro de 2014 Nome oficial 2014 Formula 1 Etihad Airways Abu Dhabi Grand Prix Local Circuito de Yas Marina, Yas, Emirados Árabes Unidos Total 55 voltas / 305.355 km Pole Piloto Nico Rosberg Mercedes Tempo 1:40.480 Volta mais rápida Piloto Daniel Ricciardo Red Bull-Renault Tempo 1:44.496 (na volta 50) Pódio Primeiro Lewis Hamilton Mercedes Segundo Felipe Massa Williams-Merce…

American cable and satellite television channel Television channel TruTVLogo since 2014CountryUnited StatesBroadcast areaWorldwideHeadquartersAtlanta, Georgia, U.S.ProgrammingPicture format1080i (HDTV)(downscaled to letterboxed 480i for the SDTV feed)OwnershipOwnerWarner Bros. DiscoveryParentWarner Bros. Discovery NetworksSister channels List Adult Swim American Heroes Channel Animal Planet Boomerang Cartoon Network Cartoonito Cinemax CNN Cooking Channel The CW Destination America Discovery Chan…

Grupos de puntos en tres dimensiones SimetríainvolutivaCs, (*)[ ] = SimetríacíclicaCnv, (*nn)[n] = SimetríadiédricaDnh, (*n22)[n,2] = Grupo poliédrico, [n,3], (*n32) Simetría tetraédricaTd, (*332)[3,3] = Simetría octaédricaOh, (*432)[4,3] = Simetría icosaédricaIh, (*532)[5,3] = La simetría cíclica en tres dimensiones[1]​ está integrada por cuatro series infinitas de grupos de puntos en tres dimensiones (n≥1) con simetría rotacional o reflexiva de multiplicidad n respecto …

2004 video game 2004 video gameTom Clancy's Ghost Recon 2Developer(s)Red Storm EntertainmentPublisher(s)UbisoftDesigner(s)Christian AllenComposer(s)Bill BrownTom SaltaSeriesTom Clancy's Ghost ReconEngineUnreal Engine 2 (PS2)[6]Platform(s)Xbox, PlayStation 2, GameCubeReleaseXbox, PS2NA: November 16, 2004 (Xbox)[2]EU: November 26, 2004[1]NA: November 30, 2004 (PS2)[3]GameCubeNA: March 15, 2005[5]EU: March 24, 2005[4]Genre(s)Tactical shooterMode(s)Sin…

Defunct weekly newspaper in India The Deccan TimesPublisherThe Deccan TimesFounded1938LanguageEnglishHeadquartersChennaiWebsitewww.thedeccantimes.in The Deccan Times is an English language news portal based In India.[1] History The Deccan Times starting in 1938 by Naganachiketh Chinnamuttevi.[1][2] The paper folded in December 1950.[2] References ^ a b Joan G. Roland. The Jewish Communities of India: Identity in a Colonial Era. Transaction Publishers. ISBN 97…

High school in Somerset County, New Jersey, United States Somerville High SchoolAddress222 Davenport StreetSomerville, Somerset County, New Jersey 08876United StatesCoordinates40°34′41″N 74°36′47″W / 40.577989°N 74.613026°W / 40.577989; -74.613026InformationTypePublic high schoolNCES School ID341509005284[1]PrincipalGerard T. FoleyFaculty92.0 FTEs[1]Enrollment1,142 (as of 2021–22)[1]Student to teacher ratio12.4:1[1]CampusSubur…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 18.218.90.172