Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
ds2-notes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
datovky
ds2-notes
Commits
e800aa61
Commit
e800aa61
authored
6 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Heaps: Intro
parent
8289b455
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
01-prelim/prelim.tex
+0
-8
0 additions, 8 deletions
01-prelim/prelim.tex
04-heaps/Makefile
+4
-0
4 additions, 0 deletions
04-heaps/Makefile
04-heaps/heaps.tex
+62
-0
62 additions, 0 deletions
04-heaps/heaps.tex
tex/adsmac.tex
+9
-0
9 additions, 0 deletions
tex/adsmac.tex
with
75 additions
and
8 deletions
01-prelim/prelim.tex
+
0
−
8
View file @
e800aa61
...
...
@@ -3,14 +3,6 @@
\singlechapter
{
1
}
\fi
\def\optable
#1
{$$
\def\cr
{
\crcr\noalign
{
\smallskip
}}
\vbox
{
\halign
{
\hbox
to
9
em
{
##
\hfil
}&
\vtop
{
\hsize
=
0
.
65
\hsize\parindent
=
0
pt
\strut
##
\strut
}
\crcr
#
1
\noalign
{
\vskip
-
\smallskipamount
}
}}$$}
\chapter
[prelim]
{
Preliminaries
}
Generally, a~data structure is a~``black box'', which contains some data and
...
...
This diff is collapsed.
Click to expand it.
04-heaps/Makefile
0 → 100644
+
4
−
0
View file @
e800aa61
TOP
=
..
PICS
=
include
../Makerules
This diff is collapsed.
Click to expand it.
04-heaps/heaps.tex
0 → 100644
+
62
−
0
View file @
e800aa61
\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
This diff is collapsed.
Click to expand it.
tex/adsmac.tex
+
9
−
0
View file @
e800aa61
...
...
@@ -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
9
em
{
##
\hfil
}&
\vtop
{
\hsize
=
0
.
65
\hsize\parindent
=
0
pt
\strut
##
\unskip\strut
}
\crcr
#
1
\noalign
{
\vskip
-
\smallskipamount
}
}}$$}
%%% Fonty %%%
\def\chapfont
{
\setfonts
[LMSansDC/24]
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment