From 0a87804856d6d8309ec2f797b690cccf23d42443 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Thu, 18 May 2017 20:31:52 +0300 Subject: [PATCH] Improve language --- chapter06.tex | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/chapter06.tex b/chapter06.tex index f95101f..b021f93 100644 --- a/chapter06.tex +++ b/chapter06.tex @@ -24,8 +24,8 @@ a greedy algorithm works. \section{Coin problem} As a first example, we consider a problem -where we are given a set of coin values -and our task is to form a sum of money +where we are given a set of coins +and our task is to form a sum of money $s$ using the coins. The values of the coins are $\{c_1,c_2,\ldots,c_k\}$, @@ -34,7 +34,7 @@ What is the minimum number of coins needed? For example, if the coins are the euro coins (in cents) \[\{1,2,5,10,20,50,100,200\}\] -and the sum of money is 520, +and $s=520$, we need at least four coins. The optimal solution is to select coins $200+200+100+20$ whose sum is 520. @@ -42,23 +42,23 @@ $200+200+100+20$ whose sum is 520. \subsubsection{Greedy algorithm} A simple greedy algorithm to the problem -is to always select the largest possible coin, -until we have constructed the required sum of money. +always selects the largest possible coin, +until the required sum of money has been constructed. This algorithm works in the example case, because we first select two 200 cent coins, then one 100 cent coin and finally one 20 cent coin. But does this algorithm always work? -It turns out that, for the set of euro coins, +It turns out that if the coins are the euro coins, the greedy algorithm \emph{always} works, i.e., it always produces a solution with the fewest possible number of coins. The correctness of the algorithm can be shown as follows: -Each coin 1, 5, 10, 50 and 100 appears -at most once in an optimal solution. -The reason for this is that if the +First, each coin 1, 5, 10, 50 and 100 appears +at most once in an optimal solution, +because if the solution would contain two such coins, we could replace them by one coin and obtain a better solution. @@ -177,8 +177,8 @@ selects the following events: \end{center} However, selecting short events is not always -a correct strategy, but the algorithm fails, -for example, in the following case: +a correct strategy. For example, the algorithm fails +in the following case: \begin{center} \begin{tikzpicture}[scale=.4] \begin{scope} @@ -189,7 +189,7 @@ for example, in the following case: \end{tikzpicture} \end{center} If we select the short event, we can only select one event. -However, it would be possible to select both the long events. +However, it would be possible to select both long events. \subsubsection*{Algorithm 2} @@ -277,7 +277,7 @@ we are given $n$ tasks with durations and deadlines and our task is to choose an order to perform the tasks. For each task, we earn $d-x$ points where $d$ is the task's deadline -and $x$ is the moment when we finished the task. +and $x$ is the moment when we finish the task. What is the largest possible total score we can obtain? @@ -371,7 +371,7 @@ Here $a>b$, so we should swap the tasks: \end{scope} \end{tikzpicture} \end{center} -Now $X$ gives $b$ points fewer and $Y$ gives $a$ points more, +Now $X$ gives $b$ points less and $Y$ gives $a$ points more, so the total score increases by $a-b > 0$. In an optimal solution, for any two consecutive tasks, @@ -382,12 +382,12 @@ sorted by their durations. \section{Minimizing sums} -We will next consider a problem where +We next consider a problem where we are given $n$ numbers $a_1,a_2,\ldots,a_n$ and our task is to find a value $x$ that minimizes the sum \[|a_1-x|^c+|a_2-x|^c+\cdots+|a_n-x|^c.\] -We will focus on the cases $c=1$ and $c=2$. +We focus on the cases $c=1$ and $c=2$. \subsubsection{Case $c=1$} @@ -415,7 +415,7 @@ Hence, the optimal solution is that $x$ is the median. If $n$ is even and there are two medians, both medians and all values between them -are optimal solutions. +are optimal choices. \subsubsection{Case $c=2$} @@ -561,7 +561,7 @@ Next we will see how Huffman coding creates the optimal code for the string \texttt{AABACDACA}. Initially, there are four nodes that correspond -to the characters in the string: +to the characters of the string: \begin{center} \begin{tikzpicture}[scale=0.9]