]> mj.ucw.cz Git - saga.git/commitdiff
Even more soft heaps.
authorMartin Mares <mj@ucw.cz>
Wed, 26 Mar 2008 16:52:34 +0000 (17:52 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 26 Mar 2008 16:52:34 +0000 (17:52 +0100)
macros.tex
opt.tex

index 96be1ccf8ebc8179a7fb862edb35b5987fb516a1..d29bd47bf724cd4ea34e91eb5e4aefb38be4efe3 100644 (file)
@@ -30,7 +30,9 @@
 \def\em#1{{\it #1\/}}
 \def\df#1{{\it #1\/}}  % when we define something
 \def\O{{\cal O}}
-\def\<#1>{\leavevmode\hbox{\it #1\/}}
+\def\<#1>{\ifmmode
+    \mathchoice{\hbox{\it #1\/}}{\hbox{\it #1\/}}{\hbox{\eightti #1\/}}{\hbox{\sixti #1\/}}%
+  \else\leavevmode\hbox{\it #1\/}\fi}
 \let\>=\noindent
 \def\qed{{\parfillskip=0pt\allowbreak\hfill\nobreak $\spadesuit$\par}}
 \def\qeditem{{\parfillskip=0pt\hfill\rlap{\hskip\rightskip\llap{$\spadesuit$}}\par}}
 \mathf@nt{\fntmathsstok}{sy}{\fntmathsssize}{cm}\skewchar\m@@f='60\scriptscriptfont2=\m@@f
 \mathf@nt{\fntmathtok}{ex}{\fntmathsize}{cm}\textfont3=\m@@f\scriptfont3=\m@@f\scriptscriptfont3=\m@@f
 \mathf@nt{\fntmathtok}{ti}{\fntmathsize}{cm}\textfont\itfam=\m@@f
+\mathf@nt{\fntmathstok}{ti}{\fntmathssize}{cm}\scriptfont\itfam=\m@@f
+\mathf@nt{\fntmathsstok}{ti}{\fntmathssize}{cm}\scriptscriptfont\itfam=\m@@f
 \mathf@nt{\fntmathtok}{sl}{\fntmathsize}{cm}\textfont\slfam=\m@@f
 \mathf@nt{\fntmathtok}{bx}{\fntmathsize}{cm}\textfont\bffam=\m@@f
 \mathf@nt{\fntmathtok}{tt}{\fntmathsize}{cm}\hyphenchar\m@@f=-1\textfont\ttfam=\m@@f
diff --git a/opt.tex b/opt.tex
index 2969ad00435c912782ebf86e0f10f7916401931e..e058beb86f433fb3905c2504e025d1f538ea9eec 100644 (file)
--- a/opt.tex
+++ b/opt.tex
@@ -241,15 +241,81 @@ Let us translate these ideas to real (pseudo)code:
 \:Recurse: call $\<Refill>(\<left>)$.
 \:If $\<ckey>(\<left>) > \<ckey>(\<right>)$, swap the sons.
 \:Move the item list from \<left> to~$v$ (implying $\<ckey>(v)=\<ckey>(\<left>)$).
-\:If $\<rank>(v)$ is odd or $\<rank>(v) > \<rank>(\<right>)+1$, recurse once more:
+\:If $\<rank>(v) > r$ and either $\<rank>(v)$ is odd or $\<rank>(v) > \<rank>(\<right>)+1$, recurse once more:
 \::Repeat steps 3--4.
 \::Append the item list from \<left> to the item list at~$v$.
 \:Clean up. If $\<ckey>(\<right>) = +\infty$:
-\::If $\<ckey>(\<left>) = +\infty$: unlink and discard both sons.
+\::If $\<ckey>(\<left>) = +\infty$, unlink and discard both sons.
 \::Otherwise relink the sons of \<left> to~$v$ and discard \<left>.
 \algout A~modified soft queue.
 \endalgo
 
+\paran{Analysis of accuracy}
+The description of the operations is complete, let us analyse their behavior
+and verify that we have delivered what we promised --- first the accuracy of
+the structure, then the time complexity of operations.
+
+We start with bounding the size of the item lists. We will assume that
+the threshold~$r$ is even.
+
+\lemma
+For every vertex~$v$ of a~soft queue, the size $\ell(v)$ of its item list
+satisfies:
+$$\ell(v) \le \max(1, 2^{\lceil \<rank>(v)/2 \rceil - r/2}).$$
+
+\proof
+Initially, all item lists contain at most one item, so the ineqality trivially
+holds. Let us continue by induction. Melds can affect it only in the favorable
+direction (they sometimes move an~item list to a~vertex of a~higher rank)
+and so do deletes (they only remove items from lists). The only potentially
+dangerous place is the \<Refill> procedure.
+
+Refilling sometimes just moves items upwards, which is safe, and sometimes it
+joins two lists into one, which generally is not. When $\<rank>(v) \le r$,
+no joining takes place and~$\ell(v)$ is still~1. Otherwise we join when either
+$\<rank>(v)$ is odd or $\<rank>(w) < \<rank>(v)-1$ for any son~$w$ of~$v$ (remember
+that both sons have the same rank). In both cases, $\lceil\<rank>(w)/2\rceil \le
+\lceil\<rank>(v)/2\rceil - 1$. By the induction hypothesis, the size of each
+of the two joined lists is at most $2^{\max(1,\lceil\<rank>(v)/2\rceil - 1 - r/2)}$,
+so the result has at most $2^{\lceil\<rank>(v)/2\rceil - r/2}$ items. (The maximum
+has disappeared since $\<rank>(v)>r$ and therefore the desired bound is at least~2.)
+\qed
+
+We will now sum the sizes of the lists over all vertices containing corrupted items.
+
+\lemma
+After~$n$ items have been inserted, the heap contains at most~$n/2^{r-3}$ corrupted
+items at any given time.
+
+\proof
+We first prove an~auxiliary claim: The master trees of all queues contain at most~$n$
+black vertices. This follows by induction: If no deletions have taken place,
+there are exactly~$n$ of them, because insertion adds one black vertex and
+melding preserves their number. A~deletion affects the master trees only when
+dismantling takes place and then it only removes a~black vertex.
+
+An~obvious upper bound on the number of corrupted items is the total size of item
+lists in all vertices of rank greater than~$r$. We already know from the previous
+lemma that the list sizes are limited by a~function of the ranks. A~complete tree
+is obviously the worst case, so we will prove that this lemma holds for the master
+tree of every queue in the heap. The actual trees can be much sparser, but the
+above claim guarantees that the total size of the master trees is bounded by the
+number of insertions properly.
+
+So let us have a~complete tree of~rank~$k$. It has exactly $2^{k-i}$ vertices
+of rank~$i$ and each such vertex contains a~list of at most~$2^{\lceil i/2\rceil - r/2}$
+items by the previous lemma. Summing over all ranks greater than~$r$, we get that
+the total number of corrupted items in this tree is at most:
+$$
+\sum_{i=r+1}^k 2^{k-i}\cdot 2^{\lceil i/2\rceil - r/2}
+= 2^{k-r/2} \cdot \sum_i 2^{\lceil i/2\rceil - i}
+\le 2^{k-r/2} \cdot \sum_i 2^{-i/2}
+$$
+
+\FIXME{Finish the proof and update the claim of the lemma.}
+
+
+\qed
 
 
 \endpart