\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsthm}

\DeclareMathOperator*{\E}{\mathbb{E}}
\let\Pr\relax
\DeclareMathOperator*{\Pr}{\mathbb{P}}

\newcommand{\eps}{\epsilon}
\newcommand{\inprod}[1]{\left\langle #1 \right\rangle}
\newcommand{\R}{\mathbb{R}}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { {\bf CS 388R: Randomized Algorithms } \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { {\em #3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{Scribe: #4}{Lecture #1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex

\begin{document}

\lecture{9 - Sep. 28, 2015}{Fall 2015}{Prof.\ Eric Price}{Tianyang Li}

\section{Overview}

In the last lecture we talked about ``The Power of Two Choices''.

In this lecture we will continue, and talk about cuckoo hashing. 

\section{The Power of Two Choices}

\begin{itemize}
\item one choice: $\Theta(\frac{\log n}{\log \log n})$ max load
\item two choices: $\Theta(\log \log n)$
\end{itemize}

The proof is by induction.

\begin{gather}
V_i(t) = \text{number of  bins at height $\geq i$ after $t$ balls} \\
V_i(t) \leq \beta_i n \text{ w.h.p.} \\
\beta_4 = \frac{1}{4} \\
\beta_{i+1} = 2 \beta_i^2 \\
Y_t =1 \text{ if ball was placed at height $i+1$ and $V_i(t+1) \leq \beta_i n$}
\end{gather}

$\Rightarrow$ $Y_t$ is stochastically dominated by
\begin{align}
Z_t \sim \{0,1\} \text{ i.i.d. pr. } \beta_i^2
\end{align}

\begin{gather}
\sum Y_t \leq \sum Z_t \\
\E[\sum Z_t] = \beta_i^2 n = \frac{\beta_{i+1} n}{2}
\end{gather}

If $\beta_{i+1} \geq C \log n$ for sufficiently large $C$, we have
\begin{align}
\Pr[\sum Z_t \geq \beta_{i+1} n] \leq e^{-\Omega(\beta_{i+1}n)} \leq O(\frac{1}{n^c})
\end{align}

\begin{gather}
E_i = \text{event that } \sum Y_t \geq \beta_{i+1} n \\
\Pr[E_i] < n^{-10} \\
Q_i = \text{event that } V_i(t) \leq \beta_i n \\
\Pr[Q_4] = 1 \\
\Pr[\bar{Q}_{i+1} | Q_i] \leq \Pr[E_i | Q_i] \\
\Rightarrow \Pr[\bar{Q}_i] \leq n^{-9} \\
\Rightarrow \Pr[\text{any } \bar{Q}_i] \leq n^{-8}
\end{gather}

The above analysis works until $\beta_i n \leq C \log n$, 
which corresponds to $i^* = \Theta(\log \log n)$.
We will analyze this case in the next lecture. 

\section{Cuckoo hashing}

``Hash each element to \emph{two} points'':
\begin{itemize}
\item $n$ vertices (bins)
\item $m$ edges (balls)
\end{itemize}

The analysis uses Erdos-Renyi graphs. 

\begin{itemize}
\item store each element in one of the locations
\item each location stores at most 1 element $\Rightarrow O(1)$ lookup, 
insertion is $O(1)$ expected
\end{itemize}

\begin{gather}
\Pr[\text{given length $k$ cycle exists} \cdots \rightarrow i_1 \rightarrow i_2 \rightarrow \cdots \rightarrow i_k \rightarrow i_1 \rightarrow \cdots ] \leq (\frac{O(m)}{n^2})^k \\
\Pr[\text{edge $e$ exists}] \leq \frac{m}{\binom{n}{2}} = O(\frac{m}{n^2}) = O(\frac{1}{n}) \\
\Pr[\text{any length $k$ cycle exists}] \leq n^k (\frac{O(m)}{n^2})^k = (O(\frac{m}{n}))^k \leq \frac{1}{100^k} \text{ if $n \geq 100m$}
\end{gather}

$\Rightarrow \Pr[\text{any cycle exists}] \leq \frac{1}{99}$, 
$\frac{98}{99}$ probability that no cycle exists for $n=O(m)$. 

If a cycle is encountered during insertion, re-hash, rebuild the hash table. 
$\E[\text{number of times we rebuild}] = O(1)$. 

\begin{align*}
\E[\text{time to build}] &= \sum_{i=1}^m \E[\text{time to insert } i^{\text{th}} \text{ element}] \\
&\leq m \cdot \E[\text{size of component of any element}] \\
&\leq 2m \cdot \E[\text{size of component of a vertex}] \\
&= O(m)
\end{align*}

This follows from a bound on the expected size of a component in an Erdos-Renyi graph $G(n, p)$ with $n$ vertices and probability $p$. 
\begin{align*}
f(n,p) &= \E[\text{size of component in } G(n,p)] \\
&\leq 1 + p \cdot (n-1) \cdot f(n-1,p) \\
&\leq 1 + np + (np)^2 + \cdots \\
&\leq \frac{1}{1-np}
\end{align*}

\bibliographystyle{alpha}

\begin{thebibliography}{42}

\bibitem[MU05]{MU05}
Michael~Mitzenmacher, Eli~Upfal.
\newblock Probability and Computing: Randomized Algorithms and Probabilistic Analysis
\newblock {\em Cambridge University Press}, 2005.

\bibitem[PR01]{PR01}
Rasmus~Pagh, Flemming~Friche~Rodler.
\newblock Cuckoo hashing
\newblock {\em Journal of Algorithms}, 51 (2004) 122-144.

\end{thebibliography}

\end{document}