Skip to content
Snippets Groups Projects
Commit e800aa61 authored by Martin Mareš's avatar Martin Mareš
Browse files

Heaps: Intro

parent 8289b455
No related branches found
No related tags found
No related merge requests found
......@@ -3,14 +3,6 @@
\singlechapter{1}
\fi
\def\optable#1{$$
\def\cr{\crcr\noalign{\smallskip}}
\vbox{\halign{
\hbox to 9em{##\hfil}&\vtop{\hsize=0.65\hsize\parindent=0pt\strut ##\strut}\crcr
#1
\noalign{\vskip-\smallskipamount}
}}$$}
\chapter[prelim]{Preliminaries}
Generally, a~data structure is a~``black box'', which contains some data and
......
TOP=..
PICS=
include ../Makerules
\ifx\chapter\undefined
\input adsmac.tex
\singlechapter{4}
\fi
\chapter[heaps]{Heaps}
\df{Heaps} are a~family of data structures for dynamic selection of a~minimum.
They maintain a~set of items, each equipped with a~\em{priority.} The priorities
are usually numeric, but we will assume that they come from some abstract universe
and they can be only compared. Besides the priority, the items can carry arbitrary
other data, usually called the \em{value} of the item.
Heaps typically support the following operations. Since a~heap cannot efficiently
find an~item by neither its priority nor value, operations which modify items get
an~abstract identifier of the item. The identifiers are assigned on insertion;
internally, they are usually pointers.
\optable{
$\opdf{Insert}(p,v)$ & Create a~new item with priority~$p$ and value~$v$ and
return its identifier. \cr
\opdf{Min} & Find an~item with minimum priority. If there are
multiple such items, pick any. If the heap is empty, return~$\emptyset$. \cr
\opdf{ExtractMin} & Find an~item with minimum priority and remove it
from the heap. If the heap is empty, return~$\emptyset$. \cr
$\opdf{Decrease}(\<id>,p)$
& Decrease priority of the item identified by~\<id> to~$p$. \cr
$\opdf{Increase}(\<id>,p)$
& Increase priority of the item identified by~\<id> to~$p$. \cr
$\opdf{Delete}(\<id>)$
& Remove the given item from the heap.
It is usually simulated by $\alg{Decrease}(\<id>,-\infty)$
followed by \alg{ExtractMin}. \cr
$\opdf{Build}((p_1,v_1),\ldots)$
& Create a~new heap containing the given items.
It is equivalent to a~sequence of \alg{Inserts} on an empty
heap, but it can be often implemented more efficiently. \cr
}
By reversing the order on priorities, we can obtain the a~maximal heap, which maintains
the maximum instead of the minimum.
\obs{
We can sort a~sequence of $n$~items by inserting them to a~heap and then calling
\alg{ExtractMin} $n$~times. The standard lower bound on comparison-based sorting implies
that at least one of \alg{Insert} and \alg{ExtractMin} must take $\Omega(\log n)$ time
amortized.
}
We can implement the heap interface using a~search tree, which yields $\Theta(\log n)$
time complexity of all operations except \alg{Build}. However, specialized constructions
presented in this chapter
will achieve $\Theta(\log n)$ amortized time for \alg{ExtractMin}, $\Theta(n)$ for \alg{Build},
and $\Theta(1)$ amortized for all other operations.
\section{Regular heaps}
\section{Binomial heaps}
\section{Lazy binomial heaps}
\section{Fibonacci heaps}
\endchapter
......@@ -269,6 +269,15 @@
% C++
\def\Cpp{C{\tt ++}}
% Tabulka operací datové struktury
\def\optable#1{$$
\def\cr{\crcr\noalign{\smallskip}}
\vbox{\halign{
\hbox to 9em{##\hfil}&\vtop{\hsize=0.65\hsize\parindent=0pt\strut ##\unskip\strut}\crcr
#1
\noalign{\vskip-\smallskipamount}
}}$$}
%%% Fonty %%%
\def\chapfont{\setfonts[LMSansDC/24]}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment