Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Datenstrukturen und Algorithm Skript
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Unger, Florian Fedor Fridolin
Datenstrukturen und Algorithm Skript
Commits
968821ca
Commit
968821ca
authored
3 years ago
by
Florian Unger
Browse files
Options
Downloads
Patches
Plain Diff
305 finalisiert
parent
ce29f15c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
305_RBT.tex
+18
-5
18 additions, 5 deletions
305_RBT.tex
Datenstrukturen_und_Algorithmen.tex
+1
-0
1 addition, 0 deletions
Datenstrukturen_und_Algorithmen.tex
bilder/RBT_aufwand.tex
+11
-7
11 additions, 7 deletions
bilder/RBT_aufwand.tex
with
30 additions
and
12 deletions
305_RBT.tex
+
18
−
5
View file @
968821ca
...
...
@@ -55,6 +55,8 @@ Die Details des Beweises sind eine Übungsaufgabe.
Umgekehrt ist die Kapazität eines RBT zwischen
$
2
^{
h'
}$
und
$
4
^{
h'
}$
.
\subsection
{
Einfügen in Red-Black-Trees
}
Dieser Abschnitt orientiert sich stark an Chris Okasakis Version:
\url
{
https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf
}
.
Da RBT insbesondere Binäre Suchbäume sind, sind die Operationen zum Suchen von Elementen, dem Finden des Maximums,
Minimums, Nachfolgers etc identisch.
...
...
@@ -113,7 +115,11 @@ Fall in binären Suchbäumen ist, muss zur Korrektheit lediglich überprüft wer
\item
die lokale Invarianz wiederhergestellt wird.
\end{itemize}
Für den ersten Punkt hilft folgende Beobachtung: Alle vier Ausgangspositionen in Abbildung
\ref
{
fig:rbt
_
balance
}
treffen
folgende Aussagen über die Ordnung in
$
D
$
:
$
a < x < b < y < c < z < d
$
, wobei wir mit
$
a,b,c,d
$
hier streng genommen alle Elemente
folgende Aussagen über die Ordnung in
$
D
$
:
\[
a < x < b < y < c < z < d,
\]
wobei wir mit
$
a,b,c,d
$
hier streng genommen alle Elemente
aus den entsprechenden Teilbäumen meinen.
Genau diese Eigenschaft wird auch im balancierten Graphen repräsentiert.
...
...
@@ -143,13 +149,13 @@ Die Laufzeit von \texttt{insert} ist immer $Θ(h)$, da allein das Suchen der ric
nimmt.
Interessanter wird die Analyse, wenn man nur Schreibzugriffe betrachtet. In dem Fall ist der best-case
$
\mathcal
{
O
}
(
1
)
$
, aber der worst-case Aufwand
$
\mathcal
{
O
}
(
log n
)
$
.
$
\mathcal
{
O
}
(
1
)
$
, aber der worst-case Aufwand
$
\mathcal
{
O
}
(
\
log
n
)
$
.
Dieses Ergebnis lässt sich noch verfeinern, da tatsächlich amortisiert
$
\mathcal
{
O
}
(
1
)
$
Schreibaufwand garantiert werden
kann:
\begin{lemma}
Bei mehrfacher, sukzessiver Anwendung von
\texttt
{
insert
}
passieren lediglich
$
\mathcal
{
O
}
(
1
)
$
Schreibaufrufe, also
Bei mehrfacher, sukzessiver Anwendung von
\emph
{
\texttt
{
insert
}
}
passieren lediglich
$
\mathcal
{
O
}
(
1
)
$
Schreibaufrufe, also
Anwendungen der Regeln (3.1), (3.3) und (3.5).
\label
{
lemma:rbt
_
amortisiert
}
\end{lemma}
...
...
@@ -160,7 +166,7 @@ kann:
einem Blatt beschreibt.
Nach der Umstrukturierung hat jedoch jeder Teilbaum mit der Wurzel
$
x
$
bzw
$
z
$
die maximale Kapazität
$
4
^{
h'
}$
, d.h.
der Teilbaum mit
$
y
$
als Wurzel hat
$
2
4
^{
h'
}$
Kapazität.
der Teilbaum mit
$
y
$
als Wurzel hat
$
2
\cdot
4
^{
h'
}$
Kapazität.
Dadurch ergeben sich beim Einfügen die in Abbildung
\ref
{
fig:RBT
_
aufwand
}
skizzierten Schreibaufwände - eine Umstrukturierung
in der
$
i.
$
Ebene ist doppelt so häufig wie in der Ebene
$
(
i
-
1
)
$
.
...
...
@@ -168,7 +174,7 @@ kann:
Akkumuliert man also über
$
k
=
2
^
l
$
mal subsequent einfügen, ergeben sich eine folgende Anzahl von Schreiboperationen:
\[
2
^
l
+
2
^{
l
-
1
}
+
2
^{
l
-
2
}
+
\dots
+
2
^
0
≤
2
^{
l
+
1
}
=
2
*
k,
2
^
l
+
2
^{
l
-
1
}
+
2
^{
l
-
2
}
+
\dots
+
2
^
0
≤
2
^{
l
+
1
}
=
2
k,
\]
und damit amortisiert über
$
k
$
Schritte
$
\mathcal
{
O
}
(
1
)
$
Aufwand.
...
...
@@ -178,5 +184,12 @@ kann:
\centering
\input
{
bilder/RBT
_
aufwand.tex
}
\label
{
fig:RBT
_
aufwand
}
\caption
{
Die Schreibaufwande beim Einfügen in einen Red-Black-Tree. In Rot in die gelegentlich auftauchenden Aufwände
zur Umstrukturierung. Tiefergehende Umstrukturierungen kommen seltener vor.
}
\end{figure}
\subsection
{
Löschen aus Red-Black-Trees*
}
Wir orientieren uns an Kimball Germanes und Matthew Mights Publikation
\url
{
https://matt.might.net/papers/germane2014deletion.pdf
}
.
TODO.
This diff is collapsed.
Click to expand it.
Datenstrukturen_und_Algorithmen.tex
+
1
−
0
View file @
968821ca
...
...
@@ -66,6 +66,7 @@
\usepackage
{
scrextend
}
%\usepackage{hhline}
\usepackage
{
appendix
}
\usepackage
{
hyperref
}
%custom macros
\makeatletter
...
...
This diff is collapsed.
Click to expand it.
bilder/RBT_aufwand.tex
+
11
−
7
View file @
968821ca
\tikzsetnextfilename
{
dynamic
_
array
_
aufwand
}
\tikzsetnextfilename
{
RBT
_
aufwand
}
\begin{tikzpicture}
\pgfplotsset
{
%
width=.8
\textwidth
,
%height=1.5\textwidth
}
\begin{axis}
[
ybar stacked,
enlargelimits=0.05,
%
enlargelimits=0.05,
ylabel=
{
Zeitaufwand
}
,
xlabel=
{$
n
$}
,
symbolic x coords=
{
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
}
,
symbolic x coords=
{
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
,19,20,21,22
}
,
nodes near coords,
nodes near coords align=
{
vertical
}
,
]
\addplot
+[ybar] coordinates
{
(1,1) (2,1) (3,1) (4,1) (5,1) (6,1) (7,1) (8,1) (9,1) (10,1)
(11,1) (12,1) (13,1) (14,1) (15,1) (16,1) (17,1) (18,1)
}
;
\addplot
+[ybar] coordinates
{
(1,0) (2,1) (3,
2
) (4,
0
) (5,
4
) (6,
0
) (7,0) (8,
0
) (9,
8
) (10,
0
)
(11,0) (12,
0
) (13,0) (14,
0
) (15,0) (16,
0
) (17,
16) (18,0
)
}
;
\legend
{
\strut
$
n
$
Einfügen,
\strut
Umstrukturierung
}
(11,1) (12,1) (13,1) (14,1) (15,1) (16,1) (17,1) (18,1)
(19,1) (20,1) (21,1) (22,1)
}
;
\addplot
+[ybar] coordinates
{
(1,0) (2,1) (3,
0
) (4,
2
) (5,
0
) (6,
1
) (7,0) (8,
3
) (9,
0
) (10,
1
)
(11,0) (12,
2
) (13,0) (14,
1
) (15,0) (16,
4
) (17,
0) (18,1) (19,0) (20,2) (21,0) (22,1
)
}
;
\legend
{
\strut
(3.3) (
\texttt
{
ins
}
),
\strut
(3.5) (
\texttt
{
balance
}
))
}
\end{axis}
\end{tikzpicture}
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