GSD Questions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

372 lines
12 KiB

\documentclass[a4paper,10pt]{article}
\usepackage{a4wide}
\usepackage{german}
\usepackage{graphicx}
\usepackage{versions}
\usepackage{amsmath}
\usepackage{color}
\usepackage{colortbl}
\usepackage{anysize}
\usepackage{enumerate}
\usepackage{verbatim}
\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)
$$
\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}
$$
\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
\subsection{Loesung}
\verbatiminput{todten/GSDSolution.java}
\fi
\section{Algorithms and Data Structures}
\subsection{In-situ List Reversal}
Describe an algorithm to reverse a singly-linked list that \emph{does not}
copy any memory cells.
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: Maintain three pointers following each other: current, next, and
previous. The first pointer is one element ahead of the second. Reverse each pointer
as you you.}
\fi
\subsection{Preorder Tree Traversal}
Consider the following tree and state the \emph{preorder} and \emph{inorder} traversal.
\begin{verbatim}
5
/ \
7 4
\ / \
1 2 9
\end{verbatim}
Which data structure do you need to implement such a traversal?
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: Preorder: 5, 7, 1, 4, 2, 9; Inorder: 7, 1, 5, 2, 4, 9.
Such traversals are implemented using a stack (explicitly or implicitly using
a recursive traversal)}
\fi
\subsection{Breadth-First-Search}
What is the BFS traversal of the tree above? Which data structure is needed to implement
such a traversal?
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: BFS: 5, 7, 4, 1, 2, 9. You need a queue to implement BFS.}
\fi
\section{Networking}
\subsection{Protocol Stacks}
Explain the major differences between the network protocols UDP, TCP and IP.
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: UDP is connectionless, offers no error correction etc., data is sent directly without handshake, typically used for real-time protocols. TCP is connection-oriented, offers error correction, flow control (also congestion control), bidirectional reliable data transfer. IP is on a different layer (Layer 3 / network layer) compared to TCP and UDP (Layer 4 / transport layer), IP is connectionless transports datagrams between endpoints, supports routing etc.}
\fi
\subsection{TCP Characteristics}
Fill the gaps with appropriate values for the corresponding TCP header fields:
\begin{figure}[htb]
\includegraphics[width=0.9\columnwidth]{images/tcp-handshake-and-flowcontrol.png}
\end{figure}
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: 2: Flags = SYN+ACK, 3: Flags = ACK, 5: ACK = sa+900, Data-Length = 400 (according to ACK in 7), 6: SEQ = sa+900, Data-Length = 100 (due to limit in (Receive) Window Size), 7: sa+1000.}
\fi
\subsection{Network Addresses}
Insert the Layer 2 and Layer 3 addresses used the following transfer from Computer A to Computer B. How many IP addresses can exist in the subnet Computer B is placed in? What is the network address of this subnet?
\begin{figure}[htb]
\includegraphics[width=0.9\columnwidth]{images/mac-address.png}
\end{figure}
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: Source IP: 1.1.1.10 (not 1.1.1.10/24), Destination IP: 2.2.15.100 (not 2.2.15.100/21), Source MAC: 11:22:33:44:55:66, Destination MAC: aa:bb:cc:dd:ee:ff (not 33:44:55:66:77:88). Number of hosts in /21 IPv4 subnet = 2046 ($2^{32-21}-2$). Network address of the IP subnet of Computer B: 2.2.8.0/21.}
\fi
\section{Regular Expressions and Shells}
\subsection{Regular Expression}
Explain the following regex:
\begin{verbatim}
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
\end{verbatim}
\ifdefined\loesung
\textcolor{red}{
{\bf Solution}: This regex describes well-formatted IPv4 addresses. Number of repetitions
given in braces, Question mark for optional choices, brackets denote ranges.}
\fi
\subsection{Extract Lines}
Write a shell command to extract lines number 101-110 from a file {\tt a.txt} and
output them (numerically sorted) to file {\tt b.txt}.
\ifdefined\loesung\textcolor{red}{
{\bf Solution}: {\tt cat a.txt | head -110 | tail -10 | sort -n > b.txt}}
\fi
\subsection{Large Files}
Write a shell command to find the file with the most number of lines in
the current directory.
\ifdefined\loesung\textcolor{red}{
{\bf Solution}: {\tt wc -l * | sort -nr} is key. One might get rid of the \emph{total} line count
and access the file name only. Optional.}
\fi
\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}
%------------------------------------------------------------------------------