From d7388c73212134c2fd9cce9370d27a7922c78c1b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 29 Mar 2008 13:50:02 +0100 Subject: [PATCH] Soft heaps: Example. --- biblio.bib | 35 +++++++++++++++++++++++++++++++++++ opt.tex | 16 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/biblio.bib b/biblio.bib index b3b6086..6e4ad37 100644 --- a/biblio.bib +++ b/biblio.bib @@ -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 a3ce088..823f5ef 100644 --- 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{% -- 2.39.5