\documentclass[a4paper]{scrartcl}

\usepackage{amssymb,amsmath}
\usepackage{hyperref}
%\usepackage[ngerman]{babel}
%%\usepackage{todonotes}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{graphicx}
\usepackage{fancybox}
\usepackage{multirow}
\usepackage{xlop}
\usepackage{wasysym}
\usepackage{enumerate}

\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}
\newtheorem{conjecture}[theorem]{Conjecture}

\newcommand{\vol}{\text{Vol}}
\newcommand{\argmin}{\text{argmin}\,}
\renewcommand\FrameCommand{\fcolorbox{black}{lightgray}} 

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

%stupid bugfix
\DeclareTextCommandDefault{\nobreakspace}{\leavevmode\nobreak\ }


\newenvironment{fminipage}%
{\begin{Sbox}\begin{minipage}}%
{\end{minipage}\end{Sbox}\fbox{\TheSbox}}

\lstset{ %
  language=C,                % the language of the code
  basicstyle=\footnotesize,           % the size of the fonts that are used for the code
  numbers=left,                   % where to put the line-numbers
  numberstyle=\tiny\color{gray},  % the style that is used for the line-numbers
  stepnumber=2,                   % the step between two line-numbers. If it's 1, each line 
                                  % will be numbered
  numbersep=5pt,                  % how far the line-numbers are from the code
  backgroundcolor=\color{white},      % choose the background color. You must add \usepackage{color}
  showspaces=false,               % show spaces adding particular underscores
  showstringspaces=false,         % underline spaces within strings
  showtabs=false,                 % show tabs within strings adding particular underscores
  frame=single,                   % adds a frame around the code
  rulecolor=\color{black},        % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  tabsize=2,                      % sets default tabsize to 2 spaces
  captionpos=b,                   % sets the caption-position to bottom
  breaklines=true,                % sets automatic line breaking
  breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
  title=\lstname,                   % show the filename of files included with \lstinputlisting;
                                  % also try caption instead of title
  keywordstyle=\color{blue},          % keyword style
  commentstyle=\color{dkgreen},       % comment style
  stringstyle=\color{mauve},         % string literal style
  escapeinside={\%*}{*)},            % if you want to add LaTeX within your code
  morekeywords={*,...},              % if you want to add more keywords to the set
  deletekeywords={...},              % if you want to delete keywords from the given language
 moredelim=[is][\bfseries]{[*}{*]} 
}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { \textbf{Blockcourse on High-Dimensional Computational Geometry} 
         \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { \emph{#3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

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

\begin{document}
%\tableofcontents

\lecture{6: Approximate Nearest Neighbor --- July 29, 2013}{Spring 2013}{Wolfgang Mulzer}{Christoph Kr\"uger, Max Wisniewski}

\section{Volume of Convex Bodies}

\subsection{Dyer-Frieze-Kamman}
A FPRAS for the Volume of a convex body $K\subseteq {\mathbb R}^d$ can be obtained as follows.

Let
\[B=K_0\dots K_{q-1} \supseteq K_q = K \supseteq B'\]
be as sequence of convex sets.

For every $K_{i-1} \supset K_i$ we take random points from $K_{i-1}$ and check if
they are in $K_i$.  In the last lecture we saw how to obtain a random cell with a
random work of polynomial length such that the distribution is uniform.

\subsection{Proof (continued).}
\subsubsection{Computing the $K_i$.}

We use an additional factor such that
\[r\cdot B=K_0\dots K_{q-1} \supseteq K_q = K \supseteq B \qquad , r=\sqrt{d}(d+1)\].

%onion:
\noindent%
\begin{minipage}{\textwidth}
\centering
\frame{
\begin{tikzpicture}
\begin{scope}
\clip (0,0) circle (3.5cm);
\fill[color=lightgray] (0,0) ellipse (3cm and 3.75cm);
\end{scope}

\draw[color=red] (0,0) ellipse (3.6 cm and 4.2 cm );
\node[color=red]at (0,-4.4cm) {$\rho _0K=r\cdot K$} ;

\foreach \x in {1,2,...,4}{
\draw[color=red] (0,0) ellipse (0.6cm+\x *0.6 cm and 0.75cm+\x *0.75 cm );
\node[color=red]at (0,-4.2cm+\x *0.75cm) {$\rho _\x K$} ;
}
\draw (0,0) circle (3.5cm);
\node at (0,3.7cm) {$r\cdot B$} ;



\draw (0,0) circle (1cm);
\node at (0,0.5cm){$B$} ;

\end{tikzpicture}
}
   \captionof{figure}{Series of $\rho_i K$ with highlighted $K_1$ }
   \label{scribe:lec6:vol:series}
\end{minipage}

Let
\begin{align*}
\rho    &= 1-\frac 1d\\
q       &= \lceil \log_{\frac 1\rho } r \rceil\\
\rho _i &= \max (\rho ^ir,1)\\
K_i     &= \rho _i K \cap rB
\end{align*}

To compute the volume of $K_q = K$ we want to compute the product

\[ \vol(K) = \overset{q}{\underset{r=1}{\prod}} \frac{\vol(K_i)}{\vol(K_{i-1})} \cdot vol(rB) \].

To determine each $\frac{\vol(K_i)}{\vol(K_{i-1})}$ we proceed as follows

\fcolorbox{black}[HTML]{E9F0E9}{\parbox{\textwidth}{%
\begin{enumerate}[1.]
   \item perform a sequence of „trials“ for each of the fractions.
      In each we
      \begin{enumerate}[(a)]
         \item perform a technical random walk on cubes of $K_{i-1}$
           for $τ$ steps that ends in some cube $c$.
         \item put small grid of cell size $γ$ on $c$ and get a random
           grid point of $x_0 \in c$.
         \item check whether $x_0 \in  K_{i-1}$
         \item and if yes whether $x_0 \in  K_i$
      \end{enumerate}
   \item use this trials to approximate $\frac
     {\vol(K_i)}{\vol(K_{i-1})}$ which is a approximation for
     $\vol(K)$
\end{enumerate}
}}

The ratio itself $\left(\frac{\vol(K_i)}{\vol(K_{i-1})}\right)$ is bounded by $\rho ^d$ due to $\frac 14 \leq  \rho ^d \leq  \frac 1e$.

The runtime altogether is 
\[O\left(d^{23} \left( \log d\right)^5 \epsilon^{-2} \log \frac 1\delta\right)  \qquad \text{for} (\epsilon,\delta )-\text{FPRAS} \].

It has been improved to
\[O\left(d^8 \epsilon^{-2} \log \left(\frac d\epsilon\right) \log \frac 1\delta \right)\].


For polytopes
the a membership oracle can be simulated (we have to consider its running time as it is no
longer an oracle) for
\begin{description}
    \item[H-polytopes] in $O(n\cdot d)$ with $n$ halfspaces by
      checking each inequality $\left< h, x \right> \leq 1$ for each
      $h \in H$ where we need $O (d)$ operations for each halfspace.

    \item[V-polytopes.]

        To check whether the point x is in the convex hull of a given set of points ($x\in CH(P)$) 
        we have to solve the following query
        \begin{align*}
          & \exists \alpha_0, \dots \alpha_n \in [0,1]\\
          \text{s.t.} \qquad &
              \alpha_1v_1 + \dots  + \alpha_nv_n &= x \\
              & \sum_{i=1}^n\alpha_i &= 1.
        \end{align*}
        This is a linear program where we are only interested in the
        existence of a solution.  A linear program can be solved by
        the ellipsoid method or the inner point method in polynomial
        time in the size of the input.


        Observe that only $\alpha_i$ are variables. The $v_i$ are
        constants given by the problem.
\end{description}

\section{Nearest Neighbor Searching}
\begin{description}
    \item[Given:]
        $P \subset {\mathbb R} ^d, |P|=n$.
    \item[Want:]
        A data Structure to Nearest-Neighbor(NN)-queries such that\\
        given $q\in {\mathbb R} ^d$,\\
        find $NN_P(Q) = \argmin_{p\in P} d(q,p)$; the nearest neighbor of $q$ in $P$.
\end{description}

\subsection{Simple Data structure}

Store all points $P$ in a list.

\begin{description}
  \item[Space:] $\Theta (n \cdot d)$ enumerating every point and its coordinates.
  \item[Query:] $\Theta (n \cdot d)$ for computing all distances of $q$ to every point $p \in P$ and
    returning the maximum.
\end{description}

The space requirement of this data structure is very good, but the query time on the other hand is bad.

\subsection{Voronoi Diagram (Ken Clarkson)}

As seen last week we can compute the Voronoi Diagram of $P$ by lifting the points
to the unit paraboloid and using a point location data structure to find the
nearest hyperplane in each step of the triangulation construction.

\begin{description}
  \item[Space:] $\Theta(n^{\lceil \frac d2 \rceil+\epsilon})$.
  \item[Query:] $O(2^O(d) \log q)$ (naive) or $d^{O(1)} \log n$
    (improved by S meiser). For any $\epsilon>0$ the constant in query
    time depends on $\epsilon$.
\end{description}
The $\epsilon$ can be removed but query time gets worse. (claimed and not verified in exercise: $O(\log^2 n)$)

In this case the query time is very good but the space requirement is exponential in the dimension.

\subsection{Improvement}
The question after these two datastructures is, whether there is some data structure in between.

But for deterministic exact algorithm this is still an open question.

\begin{conjecture}
  ``Curse of dimensionality''\\
  If we want a query time $d^{O(1)} \text{poly}(\log n)$ the space needs to depend exponentially on $d$.
\end{conjecture}


There are only partial results but there is yet no proof of the
conjecture, but Klee showed that voronoi-diagrams in $\mathbb{R}^d$
can have complexity $\Omega (n^{\lceil \frac d2 \rceil})$.

\subsection{Approximation \& Randomness}

Because there are no exact algorithms known, we look if we can get
better bounds on space- and query time if we allow randomness and and
approximate result.

\subsubsection{Definitions}

First we define the approximation of the result.

\begin{definition} (c-approximate nearest neighbor or C-NN)\\
  Given $P\subseteq {\mathbb R} ^d$, points $c\geq 1$ and $q\in {\mathbb R} ^d$.\\
  A point $p \in P$ is a c-approximate NN for $q$ iff
  $d(p,q) \subseteq c\cdot d(q,P)$.
\mbox{}\hfill$\lrcorner$
\end{definition}

And second the randomness to the algorithm.

\begin{definition} (c-approximate nearest neighbor with failure probability f)\\
   Given $P\subseteq {\mathbb R} ^d$, points $c\geq 1$ and $q\in
  {\mathbb R} ^d$, $f\in (0,1)$.\\
  Build a DS such that\\
  \[\forall q \in  {\mathbb R} ^d:\text{ Pr[DS returns a c-approximate NN for q] }\geq  1-f.\]
\mbox{}\hfill$\lrcorner$
\end{definition}

The error will be with respect to an in advanced fixed $q \in \mathbb{R}^d$.

\subsection{Solution(Indyk, Motwani \& Har Peled )}

The algorithm will be presented in two steps

\fcolorbox{black}[HTML]{E9F0E9}{\parbox{\textwidth}{%
\begin{enumerate}[1.]
\item Reduce to $a(n)$ approximate decision version.
\item Solve the decision version.
\end{enumerate}
}}

\subsubsection{Decision-version of NN-problem}
\begin{definition}(C-approximate $r$-near neighbor problem)\\
  \begin{description}
    \item[Given:] $P\subseteq {\mathbb R} ^d, c\geq 1,r\geq 0$ fixed, failure probability $f$.
    \item[Goal:] Build a Data structure that does the following:

      For a query point q 
      \begin{enumerate}[1.]
        \item if $d(q,P)\leq r$ return $p\in P$ with $d(q,p) \leq  c\cdot r$ with probability $>1-f$.
        \item if $d(q,P)\geq c\cdot r$ always return $\bot$.
        \item if $r\leq d(q,P)\leq c\cdot r$ either one can happen.
      \end{enumerate}
      \mbox{}\hfill$\lrcorner$
   \end{description}
\end{definition}

Sometimes we want a dynamic data structure which allows to insert and delete points.

\subsubsection{Reduction to decision version}
With help of the $c$-approximate $r$-near neighbor structure we want
to get a search structure for $c$-approximate nearest neighbor without
using that much more space and time for the query.

\paragraph{Naive approach}\mbox{}\\
First compute 
\begin{align*}
  d_{\max} &= \max_{p_1,p_2\in P} d(p_1,p_2)\\
  d_{\min} &= \min_{p_1,p_2\in P} d(p_1,p_2)
\end{align*}

For $i=0,\dots M$, build $c$-approximate $r_i$-near neighbors structure $Z_i$
\begin{align*}
  r_i &= c^i \frac {d_{\min}}{2\cdot c}\\
  M   &= \log_c \left( \frac {d_{\max}}{d_{\min}} 2 \left(1+\frac 1{c+1}\right)\right)
\end{align*}

which leads to:
\begin{align*}
  r_0 &= \frac {d_{\min}}{2\cdot c},\\
  r_1 &= \frac {d_{\min}}{2},\\
  r_2 &= c \cdot \frac {d_{\min}}{2},\\
  &\vdots \\
  r_M &= \frac 1c \cdot d_{\max}
\end{align*}

Let $q \in \mathbb{R}^d$ be a query.

\begin{enumerate}[(a)]
  \item if $d(q,P) \leq  \frac {d_{\min}}{2c}$
    if we query $Z_0$ with q, we got a point
    $p^* \in P: d(q,p^*) \leq  \frac{d_{\min}}2$.
    \begin{minipage}{\textwidth}
      \centering
    \frame{
    \begin{tikzpicture}
      % points and q, distance between q and p^*
      \draw[color=blue](0,0) circle (1pt);
      \draw[color=red](0.2,0.2) circle (1pt);
      \draw[color=red](0,0) --node [right] {\scriptsize{$d(q,p^*)$}} (0.2,0.2);
      \draw[color=blue](2,2) circle (1pt);
      \draw[color=blue](-3,2) circle (1pt);
      \draw[color=blue](-3,3) circle (1pt);
      \draw[color=blue] (2,-1) --node [above] {\scriptsize{$d_{min}$}} (1,-1);
      \draw[color=blue](2,-1) circle (1pt);
      \draw[color=blue](1,-1) circle (1pt);

    \end{tikzpicture}
    }
    \captionof{figure}{Case (b), if $q$ is very close to a point in $P$.}
    \label{scribe:lec6:nn:close}
    \end{minipage}

\vspace{1cm}

    It follows $p^*$ is a nearest neighbor of $q$ in $P$.\\ Otherwise
    there would be $p^{**}\in P$ with $d(q,p^{**})\leq \frac
    {d_{\min}}2\Rightarrow d(p^*,p^{**}) \leq d(p^*,q)+d(q,p^{**})
    \leq d_{\min}$ \lightning

  \item \label{scribe:lex6:nn:far} if $d(q,p) \geq  N_M = \frac 1{(c-1)}d_{\max}$ all  our datastructures $Z_i$ might return $\bot$.

\begin{minipage}{\textwidth}
  \centering
    \frame{
    \begin{tikzpicture}
      % q very far away from all P with distance $\geq  \frac 1{c-1} d_{\max}$
      \draw[color=blue](0,0) circle (1pt);
      \draw[color=blue](0.1,0) circle (1pt);
      \draw[color=blue](0,0.2) circle (1pt);
      \draw[color=blue](0.4,0.3) circle (1pt);
      \draw[color=blue](0.1,-0.2) circle (1pt);
      \draw[color=blue](0.2,-0.3) circle (1pt);
      \draw[color=blue](-0.1,0) circle (1pt);
      \draw[color=red] (10,0) circle (1pt);
      \draw[color=red] (10,0) -- node [below] {\scriptsize{$d(q,P)$}} (0.4,0.3);
    \end{tikzpicture}
    }
    \captionof{figure}{Case (c), if $q$ is far away from $P$.}
    \label{scribe:lec6:nn:farpic}
\end{minipage}

\vspace{1cm}

    Take any $p\in P$ then we know
    \[0\leq d(q,p)-d(p,nn_p(q)) \leq  d_{\max} \underbrace{\leq }_{\text{by assumption}} (c-1) d(q,p) \]
    Thus:
    \[ d(q,p)\leq  d(q,P) + (c-1)\cdot d(q,P) = c\cdot d(q,P)\]
    $\Rightarrow$ p is a $c$-approximate nearest neighbor.
  \item if $d(q,p) \in [r_0,r_M]$

    Suppose $d(q,p)\in (r_j,r_{j-1}]$ for some $j$. $r_j=c^j \frac{d_{\min}}{2c}$\\
      Now we know that 
      \begin{enumerate}[i.]
        \item for all $i\leq j-1: Z_i$ returns $\bot$ 

          (caused by $d(q,p) > r_j \Rightarrow r_{j-1} < \frac{d(q,p)}c$)
        \item for all $i\geq j+1: Z_i$ return some point $p$ with distance at most $c\cdot r_i$
        \item the only data structure where we are not sure is
          $Z_j$. %This point can be found in $\log M$ queries by binary search.
      \end{enumerate}
      Let $Z_{j^*}$ be the first Datastructure that doesn't return bottom. This can
      be found in $\log M$ queries to the $Z_i$ by using binary
      search.\\ 

      Let $p^*$ be the point returned by $Z_{j^*}$, then
      $p^*$ is $c^2$-approximate nearest neighbor,
      because it might be the case, that $Z_{j^* - 1}$ has
      a point $p'$ with $r \leq d(q,p') \leq c \cdot r$
      which has the probability to be false positive,
      then in $Z_{j^*}$ we can get at most $c$ times the distance from
      $Z_{j^*-1}$ which is $d(q,p') \leq c^2 \cdot r$.

\begin{minipage}{\textwidth}
  \centering
      \frame{
      \begin{tikzpicture}
        %points r_{j-1} \dots r_{j+1} with distance c and
        %returns. worst case r_j returns bottom point q right of r_j
        %and answer r_{j+1} return point right of itself
        \draw [color=black] (-2,0) circle (1pt) node [below] {$r_{j^* - 1}$};
        \draw [color=black] (0,0) circle (1pt) node [below] {$r_{j^*}$};
        \draw [color=black] (2,0) circle (1pt) node [below] {$r_{j^* + 1}$};
        \draw [color=black] (4,0) circle (1pt) node [below] {$r_{j^* + 2}$};

        \draw [color=black] (-2,0) -- node [above] {\scriptsize{$c$}} (0,0);
        \draw [color=black] (0,0) -- node [above] {\scriptsize{$c$}} (2,0);
        \draw [color=black] (2,0) -- node [above] {\scriptsize{$c$}} (4,0);
        
        \draw [color=black] (-1,0) circle (1pt) node [below] {$p'$};
        \draw [color=black] (1,0) circle (1pt) node [below] {$p^*$};
      \end{tikzpicture}
      }
      \captionof{figure}{Approximation result of $p^*$ in comparrison to $p'$.}
      \label{scribe:lec6:nn:csquare}
\end{minipage}
      
\end{enumerate}

{\parindent0pt\bfseries
Query Algorithm:
}

\fcolorbox{black}[HTML]{E9F0E9}{\parbox{\textwidth}{%
\begin{enumerate}[1.]
  \item Query $Z_0:$ if return a result $p^*$, we have exact NN.
  \item Query $Z_M:$ if return $\bot$, any $p\in P$ is good enough.
  \item Binary search yield $c^2$-approximate NN in $\log M$ queries
\end{enumerate}
}}
\vspace{1cm}\mbox{}\\
The big problem is that M depends on $\frac {d_{\max}}{d_{\min}}$ (the
spread) which might be arbitrary large (with arbitrary precision
in the representation).  

\[M= \log \frac {d_{\max}}{d_{\min}} \Rightarrow \text{ query time = }\log
\log \frac {d_{\max}}{d_{\min}}\]

\subsection{approximate interval nearest neighbor search}
\begin{lemma}\label{scribe:lec6:nn:interval}
  Suppose we have a c-approximate near-neighbor DS with failure
  probability $f'$, then we can do the following: Given a range
  $[a,b]$ and $γ\in (0,1)$ and $P\subseteq {\mathbb R} ^d$ we can
  build a DS for the following query: given $q\in {\mathbb R} ^d$
  \begin{enumerate}
    \item if $d(q,P) \leq  a$ this can be determined in 1 query + witness
    \item if $d(q,P)\geq b$ this can be determined in 2 queries
    \item if $d(q,p)\in [a,b]$, we can find a point $p^*\in ^P$ with
      $d(q,p^*)\leq c\cdot (1+γ) \cdot d(q,P)$ in $O(\log \frac 1γ
      \log \frac {c\cdot b}a)$ queries
  \end{enumerate}
  All this cases have the failure-probability is $f\leq O\left(\log \left(\frac 1\gamma \log \frac{cb}a\right)\right) \cdot f'$
  \mbox{}\hfill$\lrcorner$
\end{lemma}

\textbf{Proof \ref{scribe:lec6:nn:interval}.}\\
  By construction of the previous algorithm. \mbox{} \hfill$\square$

\vspace{1cm}\mbox{}\\
This is called the {\bf approximate interval nearest neighbor search.}
\\
Now we need to cluster P to obtain a sequence of reasonable interval NN-data-structures
with a structure such as in figure \ref{scribe:lec6:clus:ex} that groups $R \subseteq P$
where the points in $R$ are ``relativly'' near to each other and ``relativly'' far away
from every point not in $R$.

\begin{minipage}{\textwidth}
\centering
\frame{
\begin{tikzpicture}
  %picture of clusters

  \draw[color=blue] (0,0) circle (1cm);
  \draw[color=blue] (0,0) circle (1pt);
  \draw[color=blue] (0.1,0) circle (1pt);
  \draw[color=blue] (0,0.5) circle (1pt);
  \draw[color=blue] (0.3,0.8) circle (1pt);
  \draw[color=blue] (0.2,-0.3) circle (1pt);
  \draw[color=blue] (-0.3,0.5) circle (1pt);

  \draw[color=blue] (2,0.2) circle (0.8cm);
  \draw[color=blue] (2.1,0) circle (1pt);
  \draw[color=blue] (2,0.5) circle (1pt);
  \draw[color=blue] (2.3,0.8) circle (1pt);
  \draw[color=blue] (2.2,-0.3) circle (1pt);
  \draw[color=blue] (2.3,0.5) circle (1pt);


  \draw[color=blue] (6,-0.4) circle (1.3cm);
  \draw[color=blue] (6.1,0) circle (1pt);
  \draw[color=blue] (6,0.5) circle (1pt);
  \draw[color=blue] (6.3,0.8) circle (1pt);
  \draw[color=blue] (6.2,-0.3) circle (1pt);
  \draw[color=blue] (6.3,0.5) circle (1pt);
  

  \draw[color=blue] (10,-0.3) ellipse (1.5cm and 1.83cm);
  \draw[color=blue] (10.1,0) circle (1pt);
  \draw[color=blue] (10,0.5) circle (1pt);
  \draw[color=blue] (10.3,0.8) circle (1pt);
  \draw[color=blue] (10.2,-0.3) circle (1pt);
  \draw[color=blue] (10.3,0.5) circle (1pt);


\end{tikzpicture}
}
   \captionof{figure}{A possible clustering for a pointset}
   \label{scribe:lec6:clus:ex}
\end{minipage}

\vspace{1cm}

\subsubsection{Generating Clusters}

Next we will look at the generating of the clusters.

\begin{minipage}{\textwidth}
\centering
\frame{
  \begin{tabular}{c|c}

\begin{tikzpicture}[scale=0.5]

 \draw (5,5.5) circle (1pt);
  \draw (7,3.5) circle (1pt);
  \draw (5,2.5) circle (1pt);
  \draw (1,2) circle (1pt);
  \draw (0,1.5) circle (1pt);
  \draw (-1,2.5) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw[color=blue](5,5.5) circle (4mm) node [below] {\scriptsize{$C_1$}};
  \draw[color=blue] (5,5.5) -- (5 + 0.4, 5.5) node [right] {\scriptsize{$r_1$}};
  \draw[color=red](7,3.5) circle (4mm) node [below] {\scriptsize{$C_2$}}; 
  \draw[color=green](5,2.5) circle (4mm) node [below] {\scriptsize{$C_3$}};
  \draw[color=yellow](1,2) circle (4mm) node [below] {\scriptsize{$C_4$}};
  \draw[color=orange](0,1.5) circle (4mm) node [below] {\scriptsize{$C_5$}};
  \draw[color=black](-1,2.5) circle (4mm) node [below] {\scriptsize{$C_6$}};
  \draw[color=purple](3,8) circle (4mm) node [below] {\scriptsize{$C_7$}};

\end{tikzpicture} &


\begin{tikzpicture}[scale=0.5]

 \draw (5,5.5) circle (1pt);
  \draw (7,3.5) circle (1pt);
  \draw (5,2.5) circle (1pt);
  \draw (1,2) circle (1pt);
  \draw (0,1.5) circle (1pt);
  \draw (-1,2.5) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw[color=blue](5,5.5) circle (7mm);
     \node [color=blue] at (5,5.5-1) {\scriptsize{$C_2$}};
  \draw[color=blue] (5,5.5) --  (5+0.7,5.5) node [right] {\scriptsize{$r_2$}} ;
  \draw[color=red](7,3.5) circle (7mm);
     \node[color=blue] at (7,3.5-1) {\scriptsize{$C_3$}};
  \draw[color=green](5,2.5) circle (7mm) ;
     \node[color=green] at (5,2.5-1) {\scriptsize{$C_4$}};
  \draw[color=yellow](1,2) circle (7mm);
  \draw[color=orange](0,1.5) circle (7mm);
  \draw[color=black](-1,2.5) circle (7mm);
  \draw[color=purple](3,8) circle (7mm);
     \node[color=purple] at (3,8 - 1) {\scriptsize{$C_5$}};

 \draw [black] plot [smooth cycle] coordinates {(-2,1) (-2,3) (0,3.5) (3,2.5) (2.5,0) (0,0)} node [below] {$C_1$};

\end{tikzpicture} \\

\hline


\begin{tikzpicture}[scale=0.5]

 \draw (5,5.5) circle (1pt);
  \draw (7,3.5) circle (1pt);
  \draw (5,2.5) circle (1pt);
  \draw (1,2) circle (1pt);
  \draw (0,1.5) circle (1pt);
  \draw (-1,2.5) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw[color=blue](5,5.5) circle (12mm);
  \draw[color=blue] (5,5.5) -- node [above] {\scriptsize{$r_3$}} (5+1.2, 5.5);
  \draw[color=red](7,3.5) circle (12mm);
  \draw[color=green](5,2.5) circle (12mm);
  \draw[color=yellow](1,2) circle (12mm);
  \draw[color=orange](0,1.5) circle (12mm);
  \draw[color=black](-1,2.5) circle (12mm);
  \draw[color=purple](3,8) circle (12mm);


 \draw [black] plot [smooth cycle] coordinates {(-2.5,0) (-2.5, 4) (1,4.5) (3,2.5) (2.5,0) (0,-1)} node [below] {$C_1$};
 \draw [black] plot [smooth cycle] coordinates {(3.5,1.5) (4,3.5) (6,4.5) (7,5) (9,4.5) (9,2.5) (6.5,0.5)  } node [below] {$C_2$};

\end{tikzpicture} &


\begin{tikzpicture}[scale=0.5]

 \draw (5,5.5) circle (1pt);
  \draw (7,3.5) circle (1pt);
  \draw (5,2.5) circle (1pt);
  \draw (1,2) circle (1pt);
  \draw (0,1.5) circle (1pt);
  \draw (-1,2.5) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw (3,8) circle (1pt);
  \draw[color=blue](5,5.5) circle (17mm);
  \draw[color=blue] (5,5.5) -- node [above] {\scriptsize{$r_4$}} (5 + 1.7, 5.5);
  \draw[color=red](7,3.5) circle (17mm);
  \draw[color=green](5,2.5) circle (17mm);
  \draw[color=yellow](1,2) circle (17mm);
  \draw[color=orange](0,1.5) circle (17mm);
  \draw[color=black](-1,2.5) circle (17mm);
  \draw[color=purple](3,8) circle (17mm);
  \draw[color=purple](3,8) circle (2mm);

 \draw [black] plot [smooth cycle] coordinates {(-2.5,0) (-2.5, 4) (1,4.5) (3,2.5) (2.5,0) (0,-1)} node [below] {$C_1$};
 \draw [black] plot [smooth cycle] coordinates {(3.5,1.5) (3,5)(1,7) (2,10) (5.5, 9.5) (9,4.5) (9,2.5) (6.5,0.5)  } node [below] {$C_2$};

\end{tikzpicture} 

 \end{tabular}}
  \captionof{figure}{Clusters $CC_P$ for radi $r_1, r_2, r_3, r_4$}
  \label{scribe:lec6:clus:gen}
\end{minipage}

\vspace{1cm}\mbox{}\\
Let the balls centered a the points in $P$ grow.\\
For a fixed radius $r$ let $CC_P(r)$ be the connected components of the set
\[ \bigcup_{p\in P} B(q,r) \]
or equivalent the connected components of the graph
$G(P,E\subset P^2)$ with
\[ e=(p_1,p_2) \in E :\Leftrightarrow B(p_1,r) \cap B(p_2,r) \not= \emptyset \].
\\
This is illustraded in figure \ref{scribe:lec6:clus:gen}.\\
Let $r_{\text{med}} = \min_{r} \{ CC_p(r)$ has a component of size $\geq  \frac n2 +1\}$.
\\
Our clustering will (almost) be $CC_p(r_{\text{med}})$.
\end{document}