\documentclass[a4paper,10pt]{article}

\usepackage{a4wide}
\usepackage{german}
\usepackage{graphicx}
\usepackage{versions}
\usepackage{amsmath}
\usepackage{color}
\usepackage{colortbl}
\usepackage{anysize}
\usepackage{enumerate}

\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{listings}

\pagestyle{empty}
\setlength{\parindent}{0mm}

\begin{document}
\vspace*{-3cm}
\hspace*{-1cm}\begin{tabular}{p{.55\linewidth}p{.55\linewidth}}
  \begin{minipage}{\linewidth}
    {\bf Global Software Development} \\
    Kreiker, Pape, Rieger, Todtenh"ofer\\
    Summer Term 2018\\\\
    \today\\
  \end{minipage}
  &
  \includegraphics[width=\linewidth]{images/logo}
\end{tabular}

\begin{center}
  {\Large\bf GSD Interview Questions}\\
\end{center}

%\def\loesung{}

\section{Programming}
\subsection{Row Vectors}
Consider an $n\times m$ matrix. Calculate the absolute value for each row vector of the matrix in a programming language of your choice. Example:
$$
\left(\begin{array}{cc}
  2 & 2 \\ 4 & 4 \\ 6 & 5
\end{array}\right)
\qquad \Rightarrow \qquad\texttt{calcAbsRowVector}\qquad \Rightarrow \qquad
\left(\begin{array}{c}
  2.82 \\ 5.65 \\ 7.81
\end{array}\right)
$$
\ifdefined\loesung
\begin{verbatim}
Musterloesung here
\end{verbatim}
\fi

\subsection{Merging and Sorting}
Let $A$ and $B$ be two arrays of $n$ (unsorted) integer entries each. Write
a function that merges both arrays into a \emph{sorted} array of $2\dot n$
entries. Example:
$$
\begin{array}{lcl}
  A & = & [2, 7, 5, 34]\\
  B & = & [3, 48, 4, 72]\\
  \hline
  C & = & [2, 3, 4, 5, 7, 34, 48, 72]\\
\end{array}
$$

\ifdefined\loesung
\begin{verbatim}
Musterloesung here
\end{verbatim}
\fi

\subsection{Recursion}

Consider a herd of cows. Write a \emph{recursive} function to calculate the
sum of all legs. Use addition only (no multiplication allowed).

\ifdefined\loesung
\begin{verbatim}
Musterloesung here
\end{verbatim}
\fi

\section{Algorithms and Data Structures}

\section{Networking}

\section{Regular Expressions and Shells}

\section{Databases}
%------------------------------------------------------------------------------
\subsection{SQL statements}
%------------------------------------------------------------------------------
Write down the results of the following SQL statements on table T.
\begin{quote}
\begin{tabular}[t]{l|l|l|l}
T & A & B & C \\
\hline
 & 1 & blue & 10 \\
 & 2 & blue & 40 \\
 & 3 & pink & 30 \\
 & 4 & orange & 10 \\
 & 5 & orange & 20 \\
 & 6 & orange & 50 \\
 & 7 & orange & 50 \\
 & 8 & black & 50 \\
 & 9 & black & 40 \\
 & 10 & violet & 10 \\
 & 11 & violet & 20 \\
 & 12 & violet & 10 \\
\end{tabular}
\end{quote}

\begin{description}
  \item[a.)] {\tt SELECT B, COUNT(*) FROM T GROUP BY B HAVING SUM(C)<=40}
  \begin{quote}
  \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
    \hline
    B & COUNT(*) \\
    \hline
    \hline
    \ifdefined\loesung
      \textcolor{red}{pink} & \textcolor{red}{1} \\[0.3cm]
      \hline
      \textcolor{red}{violet} & \textcolor{red}{3} \\[0.3cm]
      \hline
      \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
      \hline
      \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
    \else
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
    \fi
    \hline
  \end{tabular}
  \end{quote}

  \item[b.)] {\tt SELECT B, COUNT(*) FROM T WHERE C>35 \\GROUP BY B HAVING COUNT(*)>=2}
  \begin{quote}
  \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
    \hline
    B & COUNT(*) \\
    \hline
    \hline
    \ifdefined\loesung
      \textcolor{red}{orange} & \textcolor{red}{2} \\[0.3cm]
      \hline
      \textcolor{red}{black} & \textcolor{red}{2} \\[0.3cm]
      \hline
      \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
      \hline
      \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
    \else
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
      \hline
      & \\[0.3cm]
    \fi
    \hline
  \end{tabular}
  \end{quote}
\end{description}

%------------------------------------------------------------------------------
\subsection{Constraints \& Integrity}
%------------------------------------------------------------------------------
The following table definition with integrity constraints are given.
\begin{quote}
{\tt
\begin{tabbing}
CREATE TABLE T1 (\=A INT, B INT, C INT,\\
\>CONSTRAINT T1\_PS PRIMARY KEY (A,B),\\
\>CONSTRAINT T1\_SK UNIQUE (C));\\
\\
CREATE TABLE T2 (A INT, B INT, C INT, D INT, E INT,\\
\>CONSTRAINT T2\_PS PRIMARY KEY (A),\\
\>CONSTRAINT T2\_FS1 FOREIGN KEY (B,C) REFERENCES T1(A,B),\\
\>CONSTRAINT T2\_FS2 FOREIGN KEY (D) REFERENCES T1(C),\\
\>CONSTRAINT T2\_E\_NN CHECK (E IS NOT NULL),\\
\>CONSTRAINT T2\_E\_13 CHECK (E BETWEEN 1 AND 3)); \\
\end{tabbing}}
\end{quote}
The table T1 and T2 contain the following tuples. NULL values are indicated by a hyphen (-).
\begin{quote}

\begin{tabular}[t]{l|l|l|l}
T1 & A & B & C \\
\hline
& 1 & 1 & 5 \\
& 2 & 2 & 10 \\
& 3 & 3 & 15 \\
& 4 & 4 & 20 \\
& 5 & 5 & 25 \\
\end{tabular}
\hspace{2cm}
\begin{tabular}[t]{l|l|l|l|l|l}
T2 & A & B & C & D & E\\
\hline
& 100 & - & - & 15 & 1 \\
& 101 & 2 & 2 & 25 & 2 \\
& 102 & 2 & 2 & - & 3 \\
& 103 & 3 & 3 & 10 & 3 \\
& 104 & 3 & 3 & 10 & 3 \\
\end{tabular}

\end{quote}

Which of the following INSERT-statements are violating/not violating the defined integrity constraints? Only one integrity constraint will be violated for each statement. Enter the name of the violated integrity constraint or ''none'' if all conditions are met.

\begin{tabular}[t]{|l|l|l|}
\hline
Nr. & INSERT-statement & Violated constraint \\[0.3cm]
\hline
1 & {\tt INSERT INTO T1 VALUES (1, 2, 5)} & \ifdefined\loesung \textcolor{red}{T1\_SK} \fi \\[0.3cm]
\hline
2 & {\tt INSERT INTO T1 VALUES (1, 2, 30)} & \ifdefined\loesung \textcolor{red}{none} \fi \\[0.3cm]
\hline
3 & {\tt INSERT INTO T1 VALUES (1, 1, 50)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
\hline
4 & {\tt INSERT INTO T1 VALUES (1, NULL, NULL)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
\hline
5 & {\tt INSERT INTO T2 VALUES (117, 2, 2, 5, 5)} & \ifdefined\loesung \textcolor{red}{T2\_E\_13} \fi \\[0.3cm]
\hline
6 & {\tt INSERT INTO T2 VALUES (109, 3, 1, 10, 3)} & \ifdefined\loesung \textcolor{red}{T2\_FS1} \fi \\[0.3cm]
\hline
7 & {\tt INSERT INTO T2 VALUES (103, 1, 1, 20, 2)} & \ifdefined\loesung \textcolor{red}{T2\_PS} \fi \\[0.3cm]
\hline
8 & {\tt INSERT INTO T2 VALUES (110, 4, 4, 35, 1)} & \ifdefined\loesung \textcolor{red}{T2\_FS2} \fi \\[0.3cm]
\hline
\end{tabular}

%------------------------------------------------------------------------------
\subsection{Relations \& DDL-statements}
%------------------------------------------------------------------------------
The following tables and DDL-statements are given. Please note: an exam with a grade other than 5.0 is passed.
\begin{figure}[htb]
  \begin{minipage}{0.30\linewidth}
    \includegraphics[width=38mm]{images/task3-chen.pdf}
  \end{minipage}
  %\hfill
  \begin{minipage}{0.55\linewidth}
    \scriptsize\lstinputlisting[numbers=none]{queries/task3-ddl.sql}
  \end{minipage}
\end{figure}

\begin{description}
  \item[a.)] What is defined in the table {\tt STUDENT}?
  \ifdefined\loesung \textcolor{red}{
\begin{itemize}
\item the student's Id is the primary key
\item a student's Id have to be between 100000 and 999999
\item the GENDER column is restricted to 'm' for male and 'f' for female
\end{itemize}}\else \vfill \fi
  \item[b.)] What is defined in the table {\tt EXAM}?
  \ifdefined\loesung \textcolor{red}{
\begin{itemize}
\item the primary key is composed of the student's Id, the attempt and the course name
\item an exam can be taken three times
\item the possible grades for an exam are 1.0, 1.3, 1.7, 2.0, 2.3, 2.7, 3.0, 3.3, 3.7, 4.0, 5.0
\item the referenced student Id must exist in the {\tt STUDENT} table ({\tt FOREIGN KEY})
\item the deletion of a student will also delete all associated exams ({\tt ON DELETE CASCADE})
\end{itemize}}\else \vfill \fi

  \item[c.)] Define a SQL query to find students (student's Id, firstname, lastname and course) who failed in the third attempt?
  \begin{quote}
  	\ifdefined\loesung \textcolor{red}{\tt SELECT S.STUDENT\_ID, S.LASTNAME, E.COURSE FROM STUDENT S, EXAM E \\ WHERE S.STUDENT\_ID=E.STUDENT\_ID AND ATTEMPT=3 AND GRADE=5}\else \vfill \fi
  \end{quote}

  \item[d.)] Define a SQL query to report the average attempts for male and female students?
  \begin{quote}
  	\ifdefined\loesung \textcolor{red}{\tt SELECT S.GENDER, AVG(ATTEMPT) FROM STUDENT S, EXAM E \\ WHERE S.STUDENT\_ID=E.STUDENT\_ID AND NOT GRADE=5 GROUP BY S.GENDER}\else \vfill \fi
  \end{quote}
\end{description}
%------------------------------------------------------------------------------
\end{document}
%------------------------------------------------------------------------------
