From 761a9128e72c270401102cb0c4215892b880dd20 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Sun, 10 Dec 2017 12:06:32 +0200 Subject: [PATCH] Small fixes --- chapter01.tex | 10 +++++----- chapter02.tex | 2 +- chapter05.tex | 14 +++++++------- chapter10.tex | 6 +++--- chapter12.tex | 2 +- chapter15.tex | 2 +- preface.tex | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/chapter01.tex b/chapter01.tex index 7eea253..60ae11a 100644 --- a/chapter01.tex +++ b/chapter01.tex @@ -35,9 +35,9 @@ straightforward and concise. Programs should be written quickly, because there is not much time available. Unlike in traditional software engineering, -the programs are short (usually at most some -hundreds of lines) and it is not needed to -maintain them after the contest. +the programs are short (usually at most a few +hundred lines of code), and they do not need to +be maintained after the contest. \section{Programming languages} @@ -56,7 +56,7 @@ Many people think that C++ is the best choice for a competitive programmer, and C++ is nearly always available in contest systems. -The benefits in using C++ are that +The benefits of using C++ are that it is a very efficient language and its standard library contains a large collection @@ -154,7 +154,7 @@ This kind of code always works, assuming that there is at least one space or newline between each element in the input. For example, the above code can read -both the following inputs: +both of the following inputs: \begin{lstlisting} 123 456 monkey \end{lstlisting} diff --git a/chapter02.tex b/chapter02.tex index 98b36c6..d062d67 100644 --- a/chapter02.tex +++ b/chapter02.tex @@ -14,7 +14,7 @@ The \key{time complexity} of an algorithm estimates how much time the algorithm will use for some input. The idea is to represent the efficiency -as an function whose parameter is the size of the input. +as a function whose parameter is the size of the input. By calculating the time complexity, we can find out whether the algorithm is fast enough without implementing it. diff --git a/chapter05.tex b/chapter05.tex index 1376afa..9fec183 100644 --- a/chapter05.tex +++ b/chapter05.tex @@ -248,7 +248,7 @@ a solution can be constructed. As an example, consider the problem of calculating the number -of ways $n$ queens can be placed to +of ways $n$ queens can be placed on an $n \times n$ chessboard so that no two queens attack each other. For example, when $n=4$, @@ -276,10 +276,10 @@ there are two possible solutions: The problem can be solved using backtracking by placing queens to the board row by row. More precisely, exactly one queen will -be placed to each row so that no queen attacks +be placed on each row so that no queen attacks any of the queens placed before. A solution has been found when all -$n$ queens have been placed to the board. +$n$ queens have been placed on the board. For example, when $n=4$, some partial solutions generated by @@ -358,7 +358,7 @@ void search(int y) { \end{lstlisting} \end{samepage} The search begins by calling \texttt{search(0)}. -The size of the board is $n$, +The size of the board is $n \times n$, and the code calculates the number of solutions to \texttt{count}. @@ -366,7 +366,7 @@ The code assumes that the rows and columns of the board are numbered from 0 to $n-1$. When the function \texttt{search} is called with parameter $y$, -it places a queen to row $y$ +it places a queen on row $y$ and then calls itself with parameter $y+1$. Then, if $y=n$, a solution has been found and the variable \texttt{count} is increased by one. @@ -446,11 +446,11 @@ the $4 \times 4$ board are numbered as follows: \end{center} Let $q(n)$ denote the number of ways -to place $n$ queens to an $n \times n$ chessboard. +to place $n$ queens on an $n \times n$ chessboard. The above backtracking algorithm tells us that, for example, $q(8)=92$. When $n$ increases, the search quickly becomes slow, -because the number of the solutions increases +because the number of solutions increases exponentially. For example, calculating $q(16)=14772512$ using the above algorithm already takes about a minute diff --git a/chapter10.tex b/chapter10.tex index afa4516..a9d9765 100644 --- a/chapter10.tex +++ b/chapter10.tex @@ -333,8 +333,8 @@ the sets $x=\{1,3,4,8\}$ and $y=\{3,6,8,9\}$, and then constructs the set $z = x \cup y = \{1,3,4,6,8,9\}$: \begin{lstlisting} -int x = (1<<1)+(1<<3)+(1<<4)+(1<<8); -int y = (1<<3)+(1<<6)+(1<<8)+(1<<9); +int x = (1<<1)|(1<<3)|(1<<4)|(1<<8); +int y = (1<<3)|(1<<6)|(1<<8)|(1<<9); int z = x|y; cout << __builtin_popcount(z) << "\n"; // 6 \end{lstlisting} @@ -804,7 +804,7 @@ that only elements $0 \ldots k$ may be removed from $S$. For example, \[\texttt{partial}(\{0,2\},1)=\texttt{value}[\{2\}]+\texttt{value}[\{0,2\}],\] -because we only may remove elements $0 \ldots 1$. +because we may only remove elements $0 \ldots 1$. We can calculate values of \texttt{sum} using values of \texttt{partial}, because \[\texttt{sum}(S) = \texttt{partial}(S,n-1).\] diff --git a/chapter12.tex b/chapter12.tex index f0b5895..eb9a0e3 100644 --- a/chapter12.tex +++ b/chapter12.tex @@ -350,7 +350,7 @@ while (!q.empty()) { Using the graph traversal algorithms, we can check many properties of graphs. Usually, both depth-first search and -bredth-first search may be used, +breadth-first search may be used, but in practice, depth-first search is a better choice, because it is easier to implement. diff --git a/chapter15.tex b/chapter15.tex index 27f44df..429c04c 100644 --- a/chapter15.tex +++ b/chapter15.tex @@ -3,7 +3,7 @@ \index{spanning tree} A \key{spanning tree} of a graph consists of -the nodes of the graph and some of the +all nodes of the graph and some of the edges of the graph so that there is a path between any two nodes. Like trees in general, spanning trees are diff --git a/preface.tex b/preface.tex index 7b77b92..64d9d40 100644 --- a/preface.tex +++ b/preface.tex @@ -5,8 +5,8 @@ The purpose of this book is to give you a thorough introduction to competitive programming. It is assumed that you already -know the basics of programming, but previous -background on competitive programming is not needed. +know the basics of programming, but no previous +background in competitive programming is needed. The book is especially intended for students who want to learn algorithms and