%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt]{article}

\usepackage{fullpage}
\usepackage{graphicx}   % need for figures
\usepackage{subfig}  % use for side-by-side figures
\usepackage{hyperref}   % use for hypertext links, including those to external documents and URLs
\usepackage{mdwlist}
\usepackage{xspace}
\usepackage[usenames,dvipsnames]{color}
\usepackage{amsmath, amsthm,amssymb}

\usepackage{mathpazo} % math & rm
%\linespread{1.05}        % Palatino needs more leading (space between lines)
\usepackage[scaled]{helvet} % ss
\usepackage{courier} % tt
%\normalfont
\usepackage[T1]{fontenc}


\begin{document}

%%%%%%%%%% TITLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
{\LARGE Homework 3} \\ \vspace{3mm}

{\large Due on December 13 }
\end{center}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace{11mm}
\noindent {\large \textsc{A: Parallel Query Processing} {\bf[25\%]}}

\noindent \rule[3mm]{12.5cm}{0.5mm}


\noindent The task is to compute the join query $Q(x_1, x_2, x_3) :- R_1(x_1), R_2(x_2), R_3(x_3)$ in parallel using $p$ machines. The query is a cartesian product of three unary
relations. Let the sizes of the relations be $N_1, N_2, N_3$ respectively.
%
\begin{enumerate}
\item{\bf [10\%]} Suppose that we compute $Q$ in a single round by distributing the data once (using the HyperCube algorithm). What is the smallest possible load (maximum amount of data each machine receives)? What is the total communication?
%
\item{\bf [10\%]} Suppose that we compute $Q$ in two rounds. In the first round we compute the cartesian product of $R_1, R_2$, and the second round the cartesian product of the intermediate result with $R_3$. What is the load in each round? What is the total communication across both rounds?
%
\item{\bf [5\%]} Which of the above two strategies achieves the best load? Which one the best total communication?
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace{11mm}
\noindent {\large \textsc{B: Data Streaming} {\bf[30\%]}}

\noindent \rule[3mm]{12.5cm}{0.5mm}


\begin{enumerate}

\item{\bf [15\%]} In {\em reservoir sampling}, we want to produce a uniform sample of size $k$ from a stream of unknown size. The algorithm works by placing the $i$-th item in the reservoir (of size $k$) with probability $k/i$ (all the first $k$ items go in the reservoir initially). Show that at any point where we have seen $n$ total items, the probability of each item being in the reservoir is $k/n$.

 
\item {\bf [15\%]} Recall the application of the Misra-Gries algorithm for the case where we want to find the top-$k$ most frequent elements. For any element $j$, let $f_j$ be its actual frequency in the stream, and $\hat{f_j}$ its estimated frequency. 
 
Show that $f_j - \frac{m-\hat{m}}{k} \leq \hat{f_j} \leq f_j$, where $\hat{m}$ is the sum of the estimated frequencies $\hat{f_j}$, and  $m$ is the total length of the stream. 
 

\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace{26mm}
\noindent {\large \textsc{C: Uncertain Data} {\bf[30\%]}}

\noindent \rule[3mm]{12.5cm}{0.5mm}

\begin{enumerate}
\item {\bf [15\%]} Consider a tuple-independent probabilistic database with the following relations: $R(A,B), S(A,C), T(A,D)$. Suppose we want to answer the boolean query 
%
$$Q() :- R(x,y), S(x,`a`), T(x,w)$$ 
Describe a {\em safe plan} for computing the probability of $Q$ if one exists; otherwise, explain why it is not possible to obtain one. 

\item {\bf [15\%]} Consider an inconsistent database, where the integrity constraints are primary keys. The database consists of two relations $R(\underline{A}, B)$ and $S(\underline{B}, C,D)$. We want to obtain the consistent answers for the query $Q(x) :- R(x,y), S(y,z,`a`)$. Write a query in SQL that computes the consistent answers for $Q$.
\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace{11mm}
\noindent {\large \textsc{D: Provenance} {\bf[15\%]}}

\noindent \rule[3mm]{12.5cm}{0.5mm}

Consider the following instance with two relations $R(A), S(A,B)$, where each tuple is tagged with a unique identifier.
%
\[ \{ R(a_1):x_1, R(a_2): x_2, S(a_1, b_1): y_1, S(a_1, b_2): y_2, S(a_2, b_2): y_3  \}\]
%
For each polynomial below, write a Boolean CQ (without inequalities or constants) having that
provenance polynomial.
\begin{enumerate}
\item $x_1 y_1 + x_1 y_2 + x_2 y_3$
\item $x_1 y_1^2 + x_1 y_2^2 + x_1 y_2 y_3 + x_2 y_2 y_3 + x_2 y_3^2$
\item $(x_1 + x_2)(y_1 + y_2 + y_3)$
\end{enumerate}

\vspace{10mm}
\noindent {\large \textsc{Deliverables}}

\noindent \rule[3mm]{4.3cm}{0.5mm}

Submit a single PDF document using \texttt{Canvas} (Homework 3). It is strongly suggested to use \LaTeX\ to write your solution.


\end{document}
