]> mj.ucw.cz Git - saga.git/commitdiff
Soft heaps: Example.
authorMartin Mares <mj@ucw.cz>
Sat, 29 Mar 2008 12:50:02 +0000 (13:50 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 29 Mar 2008 12:50:02 +0000 (13:50 +0100)
biblio.bib
opt.tex

index b3b60868f2333fb3aa28ec6c0d30e3953664f938..6e4ad37e23e4a2de669f302fcb5f61fd34f0ecca 100644 (file)
@@ -1179,3 +1179,38 @@ inproceedings{ pettie:minirand,
   pages={309--315},
   year={1978}
 }
+
+@article{ hoare:qsort,
+  title={{Quicksort}},
+  author={Hoare, Charles Anthony Richard},
+  journal={The Computer Journal},
+  volume={5},
+  number={1},
+  pages={10--16},
+  year={1962},
+  publisher={British Computer Society}
+}
+
+@article{ blum:selection,
+  title={{Time bounds for selection}},
+  author={Blum, M. and Floyd, R.W. and Pratt, V. and Rivest, R.L. and Tarjan, R.E.},
+  journal={Journal of Computer and System Sciences},
+  volume={7},
+  number={4},
+  pages={448--461},
+  year={1973}
+}
+
+@article{ hoare:qselect,
+ author = {Hoare, Charles Anthony Richard},
+ title = {Algorithm 65: find},
+ journal = {Communications of the ACM},
+ volume = {4},
+ number = {7},
+ year = {1961},
+ issn = {0001-0782},
+ pages = {321--322},
+ doi = {http://doi.acm.org/10.1145/366622.366647},
+ publisher = {ACM},
+ address = {New York, NY, USA},
+}
diff --git a/opt.tex b/opt.tex
index a3ce0889332d2c9b74152d5b58f8d9d47a82bb19..823f5ef06d058e80ab6233c9aa84787376fe3073 100644 (file)
--- a/opt.tex
+++ b/opt.tex
@@ -35,6 +35,22 @@ supports the following operations:
   (optionally signalling that the value has been corrupted).
 \endlist
 
+\examplen{Linear-time selection}
+We can use soft heaps to select the median (or generally the $k$-th smallest element)
+of a~sequence. We insert all $n$~elements to a~soft heap with error rate $\varepsilon=1/3$.
+Then we delete the minimum about $n/3$ times and we remember the current (possibly corrupted)
+value~$x$ of the last element deleted. This~$x$ is greater or equal than the current
+values of the previously deleted elements and thus also than their correct values.
+On the other hand, the current values of the $2n/3$ elements remaining in the heap
+are greater than~$x$ and at most $n/3$ of them are corrupted. Therefore at least $n/3$
+elements are greater than~$x$ and at least $n/3$ ones are smaller. Depending on the value
+of~$k$, we can always throw away one of these parts and recurse on the rest (similarly to
+the Hoare's Quickselect algorithm \cite{hoare:qselect}). The total time complexity will
+be $\O(n+(2/3)\cdot n+(2/3)^2\cdot n+\ldots) = \O(n)$. We have obtained a~nice alternative to the standard
+linear-time selection algorithm by Blum \cite{blum:selection}. The same trick can be used
+to select a~good pivot in Quicksort \cite{hoare:qsort}, leading to time complexity $\O(n\log n)$
+in the worst case.
+
 \defnn{Soft queues}
 The soft heap is built from \df{soft queues} (we will omit the adjective soft
 in the rest of this section). Each queue has a~shape of a~binary tree.\foot{%