Skip to content

Commit

Permalink
[seq] proof reading done
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinyu95 committed Sep 7, 2015
1 parent e1c7eef commit 1640083
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions datastruct/elementary/sequence/sequence-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ \subsubsection{Split a finger tree at a given position}
\end{array}
\]

And the function $splitAtL()$ is just a linear traverse, since the length of list
And the function $splitAtL$ is just a linear traverse, since the length of list
is limited not to exceed the constraint of 2-3 tree, the performance is still
ensured to be constant $O(1)$ time. Denote $L = \{x_1, x_2, ... \}$ and
$L' = \{ x_2, x_3, ...\}$.
Expand All @@ -2882,11 +2882,17 @@ \subsubsection{Split a finger tree at a given position}
{r@{\quad:\quad}l}
(\phi, x_1, \phi) & i = 0 \land L = \{x_1\} \\
(\phi, x_1, L') & i < size'(x_1) \\
(\{x_1\} \cup A, x, B) & otherwise, (A, x, B) = splitAtL(i-size'(x_1), L')
(\{x_1\} \cup A, x, B) & otherwise
\end{array}
\right .
\ee

Where

\[
(A, x, B) = splitAtL(i-size'(x_1), L')
\]

The solution of splitting is a typical divide and conquer strategy. The performance
of this algorithm is determined by the recursive case of searching in middle part
inner tree. Other cases are all constant time as we've analyzed. The depth of
Expand All @@ -2896,7 +2902,7 @@ \subsubsection{Split a finger tree at a given position}
$n$ is the number of elements stored in finger tree. The overall performance
of splitting is $O(\lg n)$.

Let's first give the Haskell program for $splitAtL()$ function
Let's first give the Haskell program for $splitAtL$ function

\lstset{language=Haskell}
\begin{lstlisting}
Expand All @@ -2906,7 +2912,7 @@ \subsubsection{Split a finger tree at a given position}
in (x:xs', y, ys)
\end{lstlisting}

Then the program for $splitAt()$, as there is already function defined in standard
Then the program for $splitAt$, as there is already function defined in standard
library with this name, we slightly change the name by adding a apostrophe.

\begin{lstlisting}
Expand Down Expand Up @@ -3082,7 +3088,7 @@ \subsubsection{Imperative random access}
\end{lstlisting}

With auxiliary algorithm that can apply function at a given position, it's trivial to implement
the \textproc{Get-At}() and \textproc{Set-At}() by passing special function for applying.
the \textproc{Get-At} and \textproc{Set-At} by passing special functions for applying.

\begin{algorithmic}
\Function{Get-At}{$T, i$}
Expand Down Expand Up @@ -3276,15 +3282,15 @@ \subsubsection{Imperative splitting}

\begin{Exercise}
\begin{enumerate}
\item Another way to realize $insertT'()$ is to force increasing the size field by one, so
that we needn't write function $tree'()$. Try to realize the algorithm by using this idea.
\item Another way to realize $insertT'$ is to force increasing the size field by one, so
that we needn't write function $tree'$. Try to realize the algorithm by using this idea.

\item Try to handle the augment size information as well as in $insertT'()$ algorithm for
the following algorithms (both functional and imperative): $extractT'()$, $appendT'()$, $removeT'()$, and $concat'()$. The $head$, $tail$,
\item Try to handle the augment size information as well as in $insertT'$ algorithm for
the following algorithms (both functional and imperative): $extractT'$, $appendT'$, $removeT'$, and $concat'$. The $head$, $tail$,
$init$ and $last$ functions should be kept unchanged. Don't refer to the download-able
programs along with this book before you take a try.

\item In the imperative \textproc{Apply-At}() algorithm, it tests if the size of the
\item In the imperative \textproc{Apply-At} algorithm, it tests if the size of the
current tree is greater than one. Why don't we test if the current tree is
a leaf? Tell the difference between these two approaches.

Expand Down

0 comments on commit 1640083

Please sign in to comment.