Skip to content
Snippets Groups Projects
Commit 9744cd1b authored by Parth Mittal's avatar Parth Mittal
Browse files

typset algorithm better

parent 5d2b3d02
No related branches found
No related tags found
No related merge requests found
...@@ -42,18 +42,16 @@ of each element in a stream of integers. We shall see that it also provides ...@@ -42,18 +42,16 @@ of each element in a stream of integers. We shall see that it also provides
us with a small set $C$ containing $F_k$, and hence lets us solve the frequent us with a small set $C$ containing $F_k$, and hence lets us solve the frequent
elements problem efficiently. elements problem efficiently.
TODO: Typeset the algorithm better. \algo{FrequencyEstimate} \algalias{Misra/Gries Algorithm}
\proc{FrequencyEstimate}$(\alpha, k)$
\algin the data stream $\alpha$, the target for the estimator $k$ \algin the data stream $\alpha$, the target for the estimator $k$
\:\em{Init}: $A \= \emptyset$. (an empty map) \:\em{Init}: $A \= \emptyset$. \cmt{an empty map}
\:\em{Process}($x$): \:\em{Process}($x$):
\: If $x \in$ keys($A$), $A[x] \= A[x] + 1$. \::If $x \in$ keys($A$), $A[x] \= A[x] + 1$.
\: Else If $\vert$keys($A$)$\vert < k - 1$, $A[x] \= 1$. \::Else If $\vert$keys($A$)$\vert < k - 1$, $A[x] \= 1$.
\: Else \::Else
\forall $a \in $~keys($A$): $A[a] \= A[a] - 1$, \forall $a \in $~keys($A$): $A[a] \= A[a] - 1$,
delete $a$ from $A$ if $A[a] = 0$. delete $a$ from $A$ if $A[a] = 0$.
\:\em{Output}: $\hat{f}_a = A[a]$ If $a \in $~keys($A$), and $\hat{f}_a = 0$ otherwise. \algout $\hat{f}_a = A[a]$ If $a \in $~keys($A$), and $\hat{f}_a = 0$ otherwise.
\endalgo \endalgo
Let us show that $\hat{f}_a$ is a good estimate for the frequency $f_a$. Let us show that $\hat{f}_a$ is a good estimate for the frequency $f_a$.
...@@ -95,6 +93,10 @@ $\vert C \vert = \vert$keys($A$)$\vert \leq k - 1$, and a key-value pair can ...@@ -95,6 +93,10 @@ $\vert C \vert = \vert$keys($A$)$\vert \leq k - 1$, and a key-value pair can
be stored in $\O(\log n + \log m)$ bits. be stored in $\O(\log n + \log m)$ bits.
\qed \qed
\subsection{The Count-Min sketch}
We will now look at a randomized streaming algorithm that performs the same task
\endchapter \endchapter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment