Mergeable heap




In computer science, a mergeable heap (also called a meldable heap) is an abstract data type, which is a heap supporting a merge operation.




Contents






  • 1 Definition


  • 2 Trivial implementation


  • 3 More efficient implementations


  • 4 See also


  • 5 References





Definition


A mergeable heap supports the usual heap operations:[1]




  • Make-Heap(), create an empty heap.


  • Insert(H,x), insert an element x into the heap H.


  • Min(H), return the minimum element, or Nil if no such element exists.


  • Extract-Min(H), extract and return the minimum element, or Nil if no such element exists.


And one more that distinguishes it:[1]



  • Merge(H1,H2), combine the elements of H1 and H2 into a single heap.


Trivial implementation


It is straightforward to implement a mergeable heap given a simple heap:


Merge(H1,H2):



  1. x ← Extract-Min(H2)


  2. while x ≠ Nil

    1. Insert(H1, x)

    2. x ← Extract-Min(H2)




This can however be wasteful as each Extract-Min(H) and Insert(H,x) typically have to maintain the heap property.



More efficient implementations


Examples of mergeable heap data structures include:



  • Binomial heap

  • Fibonacci heap

  • Leftist tree

  • Pairing heap

  • Skew heap


A more complete list with performance comparisons can be found at Heap (data structure) § Comparison of theoretic bounds for variants.


In most mergeable heap structures, mergeing is the fundamental operation on which others are based. Insertion is implemented by merging a new single-element heap with the existing heap. Deletion is implemented by merging the children of the deleted node.



See also


  • Addressable heap


References





  1. ^ ab Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2009) [1990]. Introduction to Algorithms (3rd ed.). MIT Press and McGraw-Hill. pp. 505–506. ISBN 0-262-03384-4..mw-parser-output cite.citation{font-style:inherit}.mw-parser-output .citation q{quotes:"""""""'""'"}.mw-parser-output .citation .cs1-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .citation .cs1-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration{color:#555}.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration span{border-bottom:1px dotted;cursor:help}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/12px-Wikisource-logo.svg.png")no-repeat;background-position:right .1em center}.mw-parser-output code.cs1-code{color:inherit;background:inherit;border:inherit;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;font-size:100%}.mw-parser-output .cs1-visible-error{font-size:100%}.mw-parser-output .cs1-maint{display:none;color:#33aa33;margin-left:0.3em}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-right{padding-right:0.2em}









Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

Set list of str and set name of list automaticly

刘建 (中将)