\documentclass[12pt,a4paper,portrait]{article}
\usepackage[pdftex]{graphicx}
\usepackage{vmargin}
\usepackage{amsmath}
\usepackage{amsfonts}
\setpapersize{A4}

\begin{document}

\begin{center}
Databases IK-AI, 2007 \\
0440949 Andreas van Cranenburgh
\end{center}

\section{Question 1}
Consider for example a list of student numbers and their telephone numbers:

\begin{tabular}{|c|c|}
\hline
Student nr. & Telephone nr. \\
\hline
43555 & 035432433 \\
23432 & 062343444 \\
32434 & 020345435 \\
etc. & etc. \\
\hline
\end{tabular}

\subsection{The three levels of data abstraction}
\subsubsection{Physical level}
On the physical level it is decided how these integers will be represented in memory. Storing them as "long" integers is the best. But one could also store them as binary coded decimals (BCD), which might be useful for searching substrings of digits.

In lower level programming languages (eg. C) this is up to the programmer. In higher level programming languages it is handled by the interpreter/compiler, eg. in Python:

\begin{verbatim}
telnrs = [[4355, 035432433], etc]
\end{verbatim}

\subsubsection{Logical level}
The logical level describes what kind of data are stored. You could allow multiple telephone numbers per student, or vice versa.

\subsubsection{View level}

The view level defines how the data can be accessed. In case of phonenumbers it is often not allowed to search by phonenumber, but only to search for the phonenumber belonging to a person. It is also not useful to match a part of a studentnumber or phonenumber, only exact matches count.

\subsection{The schema and its instances}
In this case the schema is simply a tuple with a 5 digit number (student ID) and a 9 digit (phone) number. The instances are the records of students and their phonenumbers.

\section{Question 2}
\includegraphics[width=0.8\textwidth]{./dbai1}

\section{Question 3}
\includegraphics[width=0.9\textwidth]{./dbai2}

\section{Question 4}
\subsection*{4.2}
\begin{gather*}
  notrented\_apartments \leftarrow \Pi _{a\#} (Apartment) - \Pi _{a\#} (Agreement) \\
  single\_apartments \leftarrow \sigma _{a-capacity=1} (Apartment) \\
  \Pi _{a-address, a-monthly-rent} (single\_apartments) 
\end{gather*}

\subsection*{4.4}
\begin{gather*}
	appcount \leftarrow am\# \mathcal{ G} count(a-date) as app-count ( \sigma _{a-date=2006} (Appointment)) \\
	maxapp \leftarrow \mathcal{ G} max(app-count) as app-count (appcount) \\
	maxam \leftarrow \sigma _{app-count=maxapp.app-count} (appcount) \\
	\Pi am-name ( \sigma _{am\#=maxam.am\#} (Apt-manager))
\end{gather*}

\subsection*{4.6}
\begin{gather*}
avg-rent \leftarrow \mathcal{G} avg(a-monthly-rent)(Apartment) \\
\Pi _{a-address, a-capacity} ( \sigma _{a-monthly-rent > avg-rent.a-monthly-rent} (Apartment))
\end{gather*}

\subsection*{4.8}
\begin{gather*}
amj \leftarrow \sigma  _{am-name = "Johnson"} (Apt-manager) \\
tj \leftarrow \Pi _{t\#} ( \sigma _{am\# = amj.am\#} (Appointment)) \\
aj \leftarrow \Pi _{a\#} (tj \Join Agreement) \\
\Pi _{a-address} (aj \Join Apartment)
\end{gather*}


\end{document}
