From: Martin Mares Date: Wed, 26 Mar 2008 16:52:34 +0000 (+0100) Subject: Even more soft heaps. X-Git-Tag: printed~156 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=513b3a929b55a72591895806bea9b1f2369b89c7;p=saga.git Even more soft heaps. --- diff --git a/macros.tex b/macros.tex index 96be1cc..d29bd47 100644 --- a/macros.tex +++ b/macros.tex @@ -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}} @@ -116,6 +118,8 @@ \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 2969ad0..e058beb 100644 --- a/opt.tex +++ b/opt.tex @@ -241,15 +241,81 @@ Let us translate these ideas to real (pseudo)code: \:Recurse: call $\(\)$. \:If $\(\) > \(\)$, swap the sons. \:Move the item list from \ to~$v$ (implying $\(v)=\(\)$). -\:If $\(v)$ is odd or $\(v) > \(\)+1$, recurse once more: +\:If $\(v) > r$ and either $\(v)$ is odd or $\(v) > \(\)+1$, recurse once more: \::Repeat steps 3--4. \::Append the item list from \ to the item list at~$v$. \:Clean up. If $\(\) = +\infty$: -\::If $\(\) = +\infty$: unlink and discard both sons. +\::If $\(\) = +\infty$, unlink and discard both sons. \::Otherwise relink the sons of \ to~$v$ and discard \. \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 \(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 \ procedure. + +Refilling sometimes just moves items upwards, which is safe, and sometimes it +joins two lists into one, which generally is not. When $\(v) \le r$, +no joining takes place and~$\ell(v)$ is still~1. Otherwise we join when either +$\(v)$ is odd or $\(w) < \(v)-1$ for any son~$w$ of~$v$ (remember +that both sons have the same rank). In both cases, $\lceil\(w)/2\rceil \le +\lceil\(v)/2\rceil - 1$. By the induction hypothesis, the size of each +of the two joined lists is at most $2^{\max(1,\lceil\(v)/2\rceil - 1 - r/2)}$, +so the result has at most $2^{\lceil\(v)/2\rceil - r/2}$ items. (The maximum +has disappeared since $\(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