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.

341 lines
11 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. \documentclass[a4paper,10pt]{article}
  2. \usepackage{a4wide}
  3. \usepackage{german}
  4. \usepackage{graphicx}
  5. \usepackage{versions}
  6. \usepackage{amsmath}
  7. \usepackage{color}
  8. \usepackage{colortbl}
  9. \usepackage{anysize}
  10. \usepackage{enumerate}
  11. \usepackage{verbatim}
  12. \usepackage[utf8]{inputenc}
  13. \usepackage{amssymb}
  14. \usepackage{amsmath}
  15. \usepackage{tikz}
  16. \usepackage{listings}
  17. \pagestyle{empty}
  18. \setlength{\parindent}{0mm}
  19. \begin{document}
  20. \vspace*{-3cm}
  21. \hspace*{-1cm}\begin{tabular}{p{.55\linewidth}p{.55\linewidth}}
  22. \begin{minipage}{\linewidth}
  23. {\bf Global Software Development} \\
  24. Kreiker, Pape, Rieger, Todtenh"ofer\\
  25. Summer Term 2018\\\\
  26. \today\\
  27. \end{minipage}
  28. &
  29. \includegraphics[width=\linewidth]{images/logo}
  30. \end{tabular}
  31. \begin{center}
  32. {\Large\bf GSD Interview Questions}\\
  33. \end{center}
  34. %\def\loesung{}
  35. \section{Programming}
  36. \subsection{Row Vectors}
  37. 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:
  38. $$
  39. \left(\begin{array}{cc}
  40. 2 & 2 \\ 4 & 4 \\ 6 & 5
  41. \end{array}\right)
  42. \qquad \Rightarrow \qquad\texttt{calcAbsRowVector}\qquad \Rightarrow \qquad
  43. \left(\begin{array}{c}
  44. 2.82 \\ 5.65 \\ 7.81
  45. \end{array}\right)
  46. $$
  47. \subsection{Merging and Sorting}
  48. Let $A$ and $B$ be two arrays of $n$ (unsorted) integer entries each. Write
  49. a function that merges both arrays into a \emph{sorted} array of $2\dot n$
  50. entries. Example:
  51. $$
  52. \begin{array}{lcl}
  53. A & = & [2, 7, 5, 34]\\
  54. B & = & [3, 48, 4, 72]\\
  55. \hline
  56. C & = & [2, 3, 4, 5, 7, 34, 48, 72]\\
  57. \end{array}
  58. $$
  59. \subsection{Recursion}
  60. Consider a herd of cows. Write a \emph{recursive} function to calculate the
  61. sum of all legs. Use addition only (no multiplication allowed).
  62. \ifdefined\loesung
  63. \subsection{Loesung}
  64. \verbatiminput{todten/GSDSolution.java}
  65. \fi
  66. \section{Algorithms and Data Structures}
  67. \subsection{In-situ List Reversal}
  68. Describe an algorithm to reverse a singly-linked list that \emph{does not}
  69. copy any memory cells.
  70. \ifdefined\loesung
  71. \textcolor{red}{
  72. {\bf Solution}: Maintain three pointers following each other: current, next, and
  73. previous. The first pointer is one element ahead of the second. Reverse each pointer
  74. as you you.}
  75. \fi
  76. \subsection{Preorder Tree Traversal}
  77. Consider the following tree and state the \emph{preorder} and \emph{inorder} traversal.
  78. \begin{verbatim}
  79. 5
  80. / \
  81. 7 4
  82. \ / \
  83. 1 2 9
  84. \end{verbatim}
  85. Which data structure do you need to implement such a traversal?
  86. \ifdefined\loesung
  87. \textcolor{red}{
  88. {\bf Solution}: Preorder: 5, 7, 1, 4, 2, 9; Inorder: 7, 1, 5, 2, 4, 9.
  89. Such traversals are implemented using a stack (explicitly or implicitly using
  90. a recursive traversal)}
  91. \fi
  92. \subsection{Breadth-First-Search}
  93. What is the BFS traversal of the tree above? Which data structure is needed to implement
  94. such a traversal?
  95. \ifdefined\loesung
  96. \textcolor{red}{
  97. {\bf Solution}: BFS: 5, 7, 4, 1, 2, 9. You need a queue to implement BFS.}
  98. \fi
  99. \section{Networking}
  100. \section{Regular Expressions and Shells}
  101. \subsection{Regular Expression}
  102. Explain the following regex:
  103. \begin{verbatim}
  104. ^(?:(?: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]?)$
  105. \end{verbatim}
  106. \ifdefined\loesung
  107. \textcolor{red}{
  108. {\bf Solution}: This regex describes well-formatted IPv4 addresses. Number of repetitions
  109. given in braces, Question mark for optional choices, brackets denote ranges.}
  110. \fi
  111. \subsection{Extract Lines}
  112. Write a shell command to extract lines number 101-110 from a file {\tt a.txt} and
  113. output them (numerically sorted) to file {\tt b.txt}.
  114. \ifdefined\loesung\textcolor{red}{
  115. {\bf Solution}: {\tt cat a.txt | head -110 | tail -10 | sort -n > b.txt}}
  116. \fi
  117. \subsection{Large Files}
  118. Write a shell command to find the file with the most number of lines in
  119. the current directory.
  120. \ifdefined\loesung\textcolor{red}{
  121. {\bf Solution}: {\tt wc -l * | sort -nr} is key. One might get rid of the \emph{total} line count
  122. and access the file name only. Optional.}
  123. \fi
  124. \section{Databases}
  125. %------------------------------------------------------------------------------
  126. \subsection{SQL statements}
  127. %------------------------------------------------------------------------------
  128. Write down the results of the following SQL statements on table T.
  129. \begin{quote}
  130. \begin{tabular}[t]{l|l|l|l}
  131. T & A & B & C \\
  132. \hline
  133. & 1 & blue & 10 \\
  134. & 2 & blue & 40 \\
  135. & 3 & pink & 30 \\
  136. & 4 & orange & 10 \\
  137. & 5 & orange & 20 \\
  138. & 6 & orange & 50 \\
  139. & 7 & orange & 50 \\
  140. & 8 & black & 50 \\
  141. & 9 & black & 40 \\
  142. & 10 & violet & 10 \\
  143. & 11 & violet & 20 \\
  144. & 12 & violet & 10 \\
  145. \end{tabular}
  146. \end{quote}
  147. \begin{description}
  148. \item[a.)] {\tt SELECT B, COUNT(*) FROM T GROUP BY B HAVING SUM(C)<=40}
  149. \begin{quote}
  150. \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
  151. \hline
  152. B & COUNT(*) \\
  153. \hline
  154. \hline
  155. \ifdefined\loesung
  156. \textcolor{red}{pink} & \textcolor{red}{1} \\[0.3cm]
  157. \hline
  158. \textcolor{red}{violet} & \textcolor{red}{3} \\[0.3cm]
  159. \hline
  160. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  161. \hline
  162. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  163. \else
  164. & \\[0.3cm]
  165. \hline
  166. & \\[0.3cm]
  167. \hline
  168. & \\[0.3cm]
  169. \hline
  170. & \\[0.3cm]
  171. \fi
  172. \hline
  173. \end{tabular}
  174. \end{quote}
  175. \item[b.)] {\tt SELECT B, COUNT(*) FROM T WHERE C>35 \\GROUP BY B HAVING COUNT(*)>=2}
  176. \begin{quote}
  177. \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
  178. \hline
  179. B & COUNT(*) \\
  180. \hline
  181. \hline
  182. \ifdefined\loesung
  183. \textcolor{red}{orange} & \textcolor{red}{2} \\[0.3cm]
  184. \hline
  185. \textcolor{red}{black} & \textcolor{red}{2} \\[0.3cm]
  186. \hline
  187. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  188. \hline
  189. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  190. \else
  191. & \\[0.3cm]
  192. \hline
  193. & \\[0.3cm]
  194. \hline
  195. & \\[0.3cm]
  196. \hline
  197. & \\[0.3cm]
  198. \fi
  199. \hline
  200. \end{tabular}
  201. \end{quote}
  202. \end{description}
  203. %------------------------------------------------------------------------------
  204. \subsection{Constraints \& Integrity}
  205. %------------------------------------------------------------------------------
  206. The following table definition with integrity constraints are given.
  207. \begin{quote}
  208. {\tt
  209. \begin{tabbing}
  210. CREATE TABLE T1 (\=A INT, B INT, C INT,\\
  211. \>CONSTRAINT T1\_PS PRIMARY KEY (A,B),\\
  212. \>CONSTRAINT T1\_SK UNIQUE (C));\\
  213. \\
  214. CREATE TABLE T2 (A INT, B INT, C INT, D INT, E INT,\\
  215. \>CONSTRAINT T2\_PS PRIMARY KEY (A),\\
  216. \>CONSTRAINT T2\_FS1 FOREIGN KEY (B,C) REFERENCES T1(A,B),\\
  217. \>CONSTRAINT T2\_FS2 FOREIGN KEY (D) REFERENCES T1(C),\\
  218. \>CONSTRAINT T2\_E\_NN CHECK (E IS NOT NULL),\\
  219. \>CONSTRAINT T2\_E\_13 CHECK (E BETWEEN 1 AND 3)); \\
  220. \end{tabbing}}
  221. \end{quote}
  222. The table T1 and T2 contain the following tuples. NULL values are indicated by a hyphen (-).
  223. \begin{quote}
  224. \begin{tabular}[t]{l|l|l|l}
  225. T1 & A & B & C \\
  226. \hline
  227. & 1 & 1 & 5 \\
  228. & 2 & 2 & 10 \\
  229. & 3 & 3 & 15 \\
  230. & 4 & 4 & 20 \\
  231. & 5 & 5 & 25 \\
  232. \end{tabular}
  233. \hspace{2cm}
  234. \begin{tabular}[t]{l|l|l|l|l|l}
  235. T2 & A & B & C & D & E\\
  236. \hline
  237. & 100 & - & - & 15 & 1 \\
  238. & 101 & 2 & 2 & 25 & 2 \\
  239. & 102 & 2 & 2 & - & 3 \\
  240. & 103 & 3 & 3 & 10 & 3 \\
  241. & 104 & 3 & 3 & 10 & 3 \\
  242. \end{tabular}
  243. \end{quote}
  244. 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.
  245. \begin{tabular}[t]{|l|l|l|}
  246. \hline
  247. Nr. & INSERT-statement & Violated constraint \\[0.3cm]
  248. \hline
  249. 1 & {\tt INSERT INTO T1 VALUES (1, 2, 5)} & \ifdefined\loesung \textcolor{red}{T1\_SK} \fi \\[0.3cm]
  250. \hline
  251. 2 & {\tt INSERT INTO T1 VALUES (1, 2, 30)} & \ifdefined\loesung \textcolor{red}{none} \fi \\[0.3cm]
  252. \hline
  253. 3 & {\tt INSERT INTO T1 VALUES (1, 1, 50)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
  254. \hline
  255. 4 & {\tt INSERT INTO T1 VALUES (1, NULL, NULL)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
  256. \hline
  257. 5 & {\tt INSERT INTO T2 VALUES (117, 2, 2, 5, 5)} & \ifdefined\loesung \textcolor{red}{T2\_E\_13} \fi \\[0.3cm]
  258. \hline
  259. 6 & {\tt INSERT INTO T2 VALUES (109, 3, 1, 10, 3)} & \ifdefined\loesung \textcolor{red}{T2\_FS1} \fi \\[0.3cm]
  260. \hline
  261. 7 & {\tt INSERT INTO T2 VALUES (103, 1, 1, 20, 2)} & \ifdefined\loesung \textcolor{red}{T2\_PS} \fi \\[0.3cm]
  262. \hline
  263. 8 & {\tt INSERT INTO T2 VALUES (110, 4, 4, 35, 1)} & \ifdefined\loesung \textcolor{red}{T2\_FS2} \fi \\[0.3cm]
  264. \hline
  265. \end{tabular}
  266. %------------------------------------------------------------------------------
  267. \subsection{Relations \& DDL-statements}
  268. %------------------------------------------------------------------------------
  269. The following tables and DDL-statements are given. Please note: an exam with a grade other than 5.0 is passed.
  270. \begin{figure}[htb]
  271. \begin{minipage}{0.30\linewidth}
  272. \includegraphics[width=38mm]{images/task3-chen.pdf}
  273. \end{minipage}
  274. %\hfill
  275. \begin{minipage}{0.55\linewidth}
  276. \scriptsize\lstinputlisting[numbers=none]{queries/task3-ddl.sql}
  277. \end{minipage}
  278. \end{figure}
  279. \begin{description}
  280. \item[a.)] What is defined in the table {\tt STUDENT}?
  281. \ifdefined\loesung \textcolor{red}{
  282. \begin{itemize}
  283. \item the student's Id is the primary key
  284. \item a student's Id have to be between 100000 and 999999
  285. \item the GENDER column is restricted to 'm' for male and 'f' for female
  286. \end{itemize}}\else \vfill \fi
  287. \item[b.)] What is defined in the table {\tt EXAM}?
  288. \ifdefined\loesung \textcolor{red}{
  289. \begin{itemize}
  290. \item the primary key is composed of the student's Id, the attempt and the course name
  291. \item an exam can be taken three times
  292. \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
  293. \item the referenced student Id must exist in the {\tt STUDENT} table ({\tt FOREIGN KEY})
  294. \item the deletion of a student will also delete all associated exams ({\tt ON DELETE CASCADE})
  295. \end{itemize}}\else \vfill \fi
  296. \item[c.)] Define a SQL query to find students (student's Id, firstname, lastname and course) who failed in the third attempt?
  297. \begin{quote}
  298. \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
  299. \end{quote}
  300. \item[d.)] Define a SQL query to report the average attempts for male and female students?
  301. \begin{quote}
  302. \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
  303. \end{quote}
  304. \end{description}
  305. %------------------------------------------------------------------------------
  306. \end{document}
  307. %------------------------------------------------------------------------------