diff --git a/chapter01.tex b/chapter01.tex index 1ce384a..12e7f01 100644 --- a/chapter01.tex +++ b/chapter01.tex @@ -849,7 +849,7 @@ $\lfloor \log_2(123)+1 \rfloor = 7$. \subsubsection{IOI} -The International Olympiad in Informatics (IOI) \cite{ioi} +The International Olympiad in Informatics (IOI) is an annual programming contest for secondary school students. Each country is allowed to send a team of @@ -951,7 +951,7 @@ whereas the last book contains advanced material. Of course, general algorithm books are also suitable for competitive programmers. -Some good books are: +Some popular books are: \begin{itemize} \item T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein: diff --git a/chapter02.tex b/chapter02.tex index 0c8e7da..56f12d6 100644 --- a/chapter02.tex +++ b/chapter02.tex @@ -313,7 +313,7 @@ assuming a time limit of one second. \begin{center} \begin{tabular}{ll} -typical input size & required time complexity \\ +input size & required time complexity \\ \hline $n \le 10$ & $O(n!)$ \\ $n \le 20$ & $O(2^n)$ \\ diff --git a/chapter03.tex b/chapter03.tex index 441ea1d..064dd44 100644 --- a/chapter03.tex +++ b/chapter03.tex @@ -664,7 +664,7 @@ string s = "monkey"; sort(s.begin(), s.end()); \end{lstlisting} Sorting a string means that the characters -in the string are sorted. +of the string are sorted. For example, the string ''monkey'' becomes ''ekmnoy''. \subsubsection{Comparison operators} @@ -775,7 +775,7 @@ an element $x$ in the array \texttt{t}: \begin{lstlisting} for (int i = 1; i <= n; i++) { - if (t[i] == x) // x found at index i + if (t[i] == x) {} // x found at index i } \end{lstlisting} @@ -816,7 +816,7 @@ The above idea can be implemented as follows: int a = 1, b = n; while (a <= b) { int k = (a+b)/2; - if (t[k] == x) // x found at index k + if (t[k] == x) {} // x found at index k if (t[k] > x) b = k-1; else a = k+1; } @@ -850,7 +850,7 @@ int k = 1; for (int b = n/2; b >= 1; b /= 2) { while (k+b <= n && t[k+b] <= x) k += b; } -if (t[k] == x) // x was found at index k +if (t[k] == x) {} // x was found at index k \end{lstlisting} The variables $k$ and $b$ contain the position @@ -893,7 +893,7 @@ $\texttt{ok}(x)$ & \texttt{false} & \texttt{false} \end{center} \noindent -Now, the value $k$ can be found using binary search: +Now, the value of $k$ can be found using binary search: \begin{lstlisting} int x = -1; @@ -923,7 +923,7 @@ the total time complexity is $O(n \log z)$. Binary search can also be used to find the maximum value for a function that is first increasing and then decreasing. -Our task is to find a value $k$ such that +Our task is to find a position $k$ such that \begin{itemize} \item diff --git a/chapter04.tex b/chapter04.tex index b0edcd9..c0443f4 100644 --- a/chapter04.tex +++ b/chapter04.tex @@ -141,7 +141,7 @@ cout << c << "\n"; // tiva A \key{set} is a data structure that maintains a collection of elements. -The basic operations in a set are element +The basic operations of sets are element insertion, search and removal. C++ contains two set implementations: @@ -149,7 +149,7 @@ C++ contains two set implementations: The structure \texttt{set} is based on a balanced binary tree and the time complexity of its operations is $O(\log n)$. -The structure \texttt{unordered\_set} uses a hash table, +The structure \texttt{unordered\_set} uses hashing, and the time complexity of its operations is $O(1)$ on average. The choice which set implementation to use @@ -262,7 +262,7 @@ the structure binary tree and accessing elements takes $O(\log n)$ time, while the structure -\texttt{unordered\_map} uses a hash map +\texttt{unordered\_map} uses hashing and accessing elements takes $O(1)$ time on average. The following code creates a map @@ -383,7 +383,7 @@ A shorter way to write the code is as follows: auto it = s.begin(); \end{lstlisting} The element to which an iterator points -can be accessed through the \texttt{*} symbol. +can be accessed using the \texttt{*} symbol. For example, the following code prints the first element in the set: @@ -530,9 +530,9 @@ cout << (a^b) << "\n"; // 1001101110 A \texttt{deque} is a dynamic array whose size can be changed at both ends of the array. -Like a vector, a deque contains the functions +Like a vector, a deque provides the functions \texttt{push\_back} and \texttt{pop\_back}, but -it also contains the functions +it also provides the functions \texttt{push\_front} and \texttt{pop\_front} that are not available in a vector. @@ -610,7 +610,7 @@ either the minimum or maximum element. The time complexity is $O(\log n)$ for insertion and removal and $O(1)$ for retrieval. -While a set structure efficiently supports +While an ordered set efficiently supports all the operations of a priority queue, the benefit in using a priority queue is that it has smaller constant factors. diff --git a/chapter05.tex b/chapter05.tex index 56e946e..0295099 100644 --- a/chapter05.tex +++ b/chapter05.tex @@ -22,6 +22,9 @@ dynamic programming, may be needed. We first consider the problem of generating all subsets of a set of $n$ elements. +For example, the subsets of $\{1,2,3\}$ are +$\emptyset$, $\{1\}$, $\{2\}$, $\{3\}$, $\{1,2\}$, +$\{1,3\}$, $\{2,3\}$ and $\{1,2,3\}$. There are two common methods for this: we can either implement a recursive search or use bit operations of integers. @@ -33,7 +36,7 @@ of a set is to use recursion. The following function generates the subsets of the set $\{1,2,\ldots,n\}$. -The function maintains a vector +The function maintains a vector \texttt{v} that will contain the elements of each subset. The search begins when the function is called with parameter 1. @@ -164,6 +167,9 @@ for (int b = 0; b < (1<