Skip to content

Commit f36c802

Browse files
committed
Merge branch 'jon-suggestion'
2 parents b1a79a0 + d290a08 commit f36c802

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/QuantitativePrimer.pdf

2.22 KB
Binary file not shown.

src/QuantitativePrimer.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
% C: Increment with minor error corrections and additions
99
% When B is incrememted, C is reset to zero
1010
% When A is incrememted, B and C is reset to zero
11-
\newcommand{\docversion}{V1.1.4}
11+
\newcommand{\docversion}{V1.1.5}
1212
\begin{document}
1313

1414
%\doublespacing
@@ -67,7 +67,7 @@
6767

6868
\vfill
6969
\noindent
70-
Special thanks to Luke Miller and Robert Tillman for some clever solutions,
70+
Special thanks to Luke Miller, Robert Tillman, and Jonathan Hon for some clever solutions,
7171
William Xing for catching typos and suggestions on soft questions,
7272
Iztok Pizorn for corrections in the code,
7373
Nita Bester for proofreading and support,

src/answers/arraymissingnumber_a.tex

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,25 @@
4444
\]
4545
where $B_j$ represents the Bernoulli numbers, or calculate them numerically.
4646

47+
An alternative way to answer this question was suggested by Jonathan Hon.
48+
It involves initialising a boolean array of size $n$, with all the elements set to \verb+false+.
49+
Then you loop over the array of integers and use each integer to set the value in the corresponding position (or position minus one for zero-indexed arrays) in the boolean array to \verb+true+.
50+
Now you can loop over the boolean array and look for the values that are \verb+false+, revealing the missing numbers.
4751

48-
\end{subanswer}
52+
The difference between the two approaches is the complexity.
53+
The first approach has space complexity of $O(k)$ since you only have to store the $k$ equations, but you also have to solve them.
54+
The computational complexity of solving them is difficult to calculate, and it will depend on the algorithm you use.
55+
Worst case scenario is the brute-force approach, where you try all the possible values,
56+
which will have a worst-case complexity of $O(n!/((n-k)!k!))$, as we have to try all the combinations of $k$ integers.
57+
The second approach has a space complexity of $O(n)$, since you have to store the boolean array, and a computational complexity of $O(n)$.
58+
There is, however, more nuance to this method. If, instead of using a boolean array, you use an integer array and put the integers in their corresponding places, you will end up sorting the numbers.
59+
The best sorting algorithms require $O(n \log(n))$ operations.
60+
Have you cheated?
61+
Kind of, but that is because you have more information than you would when sorting an arbitrary list of numbers; you know that the numbers are the integers from 1 to $n$, and you know there are only $k$ missing.
62+
This is something that you may have to debate with the interviewer, but usually discussions like these are a sign that the interview is going well.
63+
A question may have a \emph{best} or \emph{right} answer, but this isn't necessarily the answer the interviewer wants to hear.
64+
Often you have to allow the interviewer to guide you to the answer they want.
4965

5066

67+
\end{subanswer}
5168

0 commit comments

Comments
 (0)