<?xml version="1.0" encoding="UTF-8"?>

<record version="3" id="2707">
 <title>heap</title>
 <name>Heap</name>
 <created>2002-02-25 22:07:36</created>
 <modified>2004-05-17 13:46:00</modified>
 <type>Data Structure</type>
 <creator id="409" name="mps"/>
 <author id="409" name="mps"/>
 <author id="6" name="Logan"/>
 <classification>
	<category scheme="msc" code="68P10"/>
	<category scheme="msc" code="68P20"/>
	<category scheme="msc" code="68P05"/>
 </classification>
 <defines>
	<concept>heap property</concept>
 </defines>
 <related>
	<object name="BinaryTree"/>
	<object name="BalancedTree"/>
	<object name="HeapInsertionAlgorithm"/>
	<object name="HeapRemovalAlgorithm"/>
	<object name="Heapsort"/>
 </related>
 <preamble>\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[all]{xy}</preamble>
 <content>Let $\preceq$ be a total order on some set $A$.  A \emph{heap} is then a data structure for storing elements in $A$.  A heap is a balanced binary tree, with the property that if $y$ is a descendent of $x$ in the heap, then $x\preceq y$ must hold.  This property is often referred to as the \emph{heap property}.

If $\preceq$ is $\leq$, then the root of the heap always gives the smallest element of the heap, and if $\preceq$ is $\geq$, then the root of the heap always gives the largest element of the heap.  More generally, the root of the heap is some $a\in A$ such that $a\preceq x$ holds for all $x$ in the heap.

For example, the following heap represents the multiset $\left\{ 1, 2, 4, 4, 6, 8 \right\}$ for the total order $\geq$ on $\mathbb{Z}$.

$$
\xymatrix{
&amp;&amp;&amp; 8 \ar@{-}[dll] \ar@{-}[drr] \\
&amp; 4 \ar@{-}[dl] \ar@{-}[dr] &amp;&amp;&amp;&amp; 6 \ar@{-}[dl] \\
1 &amp;&amp; 4 &amp;&amp; 2
}
$$

Due to the heap property, heaps have a very elegant application to the sorting problem.  The heapsort is an in-place sorting algorithm centered entirely around a heap.  Heaps are also used to implement priority queues.</content>
</record>
