Improve language

This commit is contained in:
Antti H S Laaksonen 2017-05-18 20:31:52 +03:00
parent d3c0e57236
commit 0a87804856
1 changed files with 18 additions and 18 deletions

View File

@ -24,8 +24,8 @@ a greedy algorithm works.
\section{Coin problem} \section{Coin problem}
As a first example, we consider a problem As a first example, we consider a problem
where we are given a set of coin values where we are given a set of coins
and our task is to form a sum of money and our task is to form a sum of money $s$
using the coins. using the coins.
The values of the coins are The values of the coins are
$\{c_1,c_2,\ldots,c_k\}$, $\{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) For example, if the coins are the euro coins (in cents)
\[\{1,2,5,10,20,50,100,200\}\] \[\{1,2,5,10,20,50,100,200\}\]
and the sum of money is 520, and $s=520$,
we need at least four coins. we need at least four coins.
The optimal solution is to select coins The optimal solution is to select coins
$200+200+100+20$ whose sum is 520. $200+200+100+20$ whose sum is 520.
@ -42,23 +42,23 @@ $200+200+100+20$ whose sum is 520.
\subsubsection{Greedy algorithm} \subsubsection{Greedy algorithm}
A simple greedy algorithm to the problem A simple greedy algorithm to the problem
is to always select the largest possible coin, always selects the largest possible coin,
until we have constructed the required sum of money. until the required sum of money has been constructed.
This algorithm works in the example case, This algorithm works in the example case,
because we first select two 200 cent coins, because we first select two 200 cent coins,
then one 100 cent coin and finally one 20 cent coin. then one 100 cent coin and finally one 20 cent coin.
But does this algorithm always work? 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., the greedy algorithm \emph{always} works, i.e.,
it always produces a solution with the fewest it always produces a solution with the fewest
possible number of coins. possible number of coins.
The correctness of the algorithm can be The correctness of the algorithm can be
shown as follows: shown as follows:
Each coin 1, 5, 10, 50 and 100 appears First, each coin 1, 5, 10, 50 and 100 appears
at most once in an optimal solution. at most once in an optimal solution,
The reason for this is that if the because if the
solution would contain two such coins, solution would contain two such coins,
we could replace them by one coin and we could replace them by one coin and
obtain a better solution. obtain a better solution.
@ -177,8 +177,8 @@ selects the following events:
\end{center} \end{center}
However, selecting short events is not always However, selecting short events is not always
a correct strategy, but the algorithm fails, a correct strategy. For example, the algorithm fails
for example, in the following case: in the following case:
\begin{center} \begin{center}
\begin{tikzpicture}[scale=.4] \begin{tikzpicture}[scale=.4]
\begin{scope} \begin{scope}
@ -189,7 +189,7 @@ for example, in the following case:
\end{tikzpicture} \end{tikzpicture}
\end{center} \end{center}
If we select the short event, we can only select one event. 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} \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. and our task is to choose an order to perform the tasks.
For each task, we earn $d-x$ points For each task, we earn $d-x$ points
where $d$ is the task's deadline 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 What is the largest possible total score
we can obtain? we can obtain?
@ -371,7 +371,7 @@ Here $a>b$, so we should swap the tasks:
\end{scope} \end{scope}
\end{tikzpicture} \end{tikzpicture}
\end{center} \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$. so the total score increases by $a-b > 0$.
In an optimal solution, In an optimal solution,
for any two consecutive tasks, for any two consecutive tasks,
@ -382,12 +382,12 @@ sorted by their durations.
\section{Minimizing sums} \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$ we are given $n$ numbers $a_1,a_2,\ldots,a_n$
and our task is to find a value $x$ and our task is to find a value $x$
that minimizes the sum that minimizes the sum
\[|a_1-x|^c+|a_2-x|^c+\cdots+|a_n-x|^c.\] \[|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$} \subsubsection{Case $c=1$}
@ -415,7 +415,7 @@ Hence, the optimal solution is that $x$
is the median. is the median.
If $n$ is even and there are two medians, If $n$ is even and there are two medians,
both medians and all values between them both medians and all values between them
are optimal solutions. are optimal choices.
\subsubsection{Case $c=2$} \subsubsection{Case $c=2$}
@ -561,7 +561,7 @@ Next we will see how Huffman coding creates
the optimal code for the string the optimal code for the string
\texttt{AABACDACA}. \texttt{AABACDACA}.
Initially, there are four nodes that correspond Initially, there are four nodes that correspond
to the characters in the string: to the characters of the string:
\begin{center} \begin{center}
\begin{tikzpicture}[scale=0.9] \begin{tikzpicture}[scale=0.9]