|
@ -93,9 +93,10 @@ Describe an algorithm to reverse a singly-linked list that \emph{does not} |
|
|
copy any memory cells. |
|
|
copy any memory cells. |
|
|
|
|
|
|
|
|
\ifdefined\loesung |
|
|
\ifdefined\loesung |
|
|
|
|
|
\textcolor{red}{ |
|
|
{\bf Solution}: Maintain three pointers following each other: current, next, and |
|
|
{\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 |
|
|
previous. The first pointer is one element ahead of the second. Reverse each pointer |
|
|
as you you. |
|
|
|
|
|
|
|
|
as you you.} |
|
|
\fi |
|
|
\fi |
|
|
|
|
|
|
|
|
\subsection{Preorder Tree Traversal} |
|
|
\subsection{Preorder Tree Traversal} |
|
@ -109,21 +110,49 @@ Consider the following tree and state the \emph{preorder} and \emph{inorder} tra |
|
|
\end{verbatim} |
|
|
\end{verbatim} |
|
|
Which data structure do you need to implement such a traversal? |
|
|
Which data structure do you need to implement such a traversal? |
|
|
\ifdefined\loesung |
|
|
\ifdefined\loesung |
|
|
|
|
|
\textcolor{red}{ |
|
|
{\bf Solution}: Preorder: 5, 7, 1, 4, 2, 9; Inorder: 7, 1, 5, 2, 4, 9. |
|
|
{\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 |
|
|
Such traversals are implemented using a stack (explicitly or implicitly using |
|
|
a recursive traversal) |
|
|
|
|
|
|
|
|
a recursive traversal)} |
|
|
\fi |
|
|
\fi |
|
|
|
|
|
|
|
|
\subsection{Breadth-First-Search} |
|
|
\subsection{Breadth-First-Search} |
|
|
What is the BFS traversal of the tree above? Which data structure is needed to implement |
|
|
What is the BFS traversal of the tree above? Which data structure is needed to implement |
|
|
such a traversal? |
|
|
such a traversal? |
|
|
\ifdefined\loesung |
|
|
\ifdefined\loesung |
|
|
{\bf Solution}: BFS: 5, 7, 4, 1, 2, 9. You need a queue to implement BFS. |
|
|
|
|
|
|
|
|
\textcolor{red}{ |
|
|
|
|
|
{\bf Solution}: BFS: 5, 7, 4, 1, 2, 9. You need a queue to implement BFS.} |
|
|
\fi |
|
|
\fi |
|
|
|
|
|
|
|
|
\section{Networking} |
|
|
\section{Networking} |
|
|
|
|
|
|
|
|
\section{Regular Expressions and Shells} |
|
|
\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} |
|
|
\section{Databases} |
|
|
%------------------------------------------------------------------------------ |
|
|
%------------------------------------------------------------------------------ |
|
|