Skip to content

Commit

Permalink
[seq] proof read splitAt
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinyu95 committed Sep 6, 2015
1 parent b78b62d commit e1c7eef
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions datastruct/elementary/sequence/sequence-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1886,8 +1886,8 @@ \subsection{Handling the ill-formed finger tree when removing}
return (elem(n), flat(root))
\end{lstlisting}

Member function \texttt{Tree.empty()} returns true if all the three parts - the front finger,
the rear finger and the middle part inner tree - are empty. We put a flag \texttt{Node.leaf}
Member function \texttt{Tree.empty()} returns true if both the front finger and
the rear finger are empty. We put a flag \texttt{Node.leaf}
to mark if a node is a leaf or compound node. The exercise of this section asks the reader
to consider some alternatives.

Expand Down Expand Up @@ -1953,7 +1953,7 @@ \subsection{append element to the tail of the sequence}
\index{Finger tree!Append to tail}

Because finger tree is symmetric, we can give the realization of appending element on tail
by referencing to $insertT()$ algorithm.
by referencing to $insertT$ algorithm.

\be
appendT(T, x) = \left \{
Expand Down Expand Up @@ -2042,8 +2042,8 @@ \subsection{append element to the tail of the sequence}
\subsection{remove element from the tail of the sequence}
\index{Finger tree!Remove from tail}

Similar to $appendT()$, we can realize the algorithm which remove the last element from
finger tree in symmetric manner of $extractT()$.
Similar to $appendT$, we can realize the algorithm which remove the last element from
finger tree in symmetric manner of $extractT$.

We denote the non-empty, non-leaf finger tree as $tree(F, M, R)$, where $F$ is the
front finger, $M$ is the middle part inner tree, and $R$ is the rear finger.
Expand Down Expand Up @@ -2148,7 +2148,7 @@ \subsection{concatenate}
as well as the rear finger of $M_1$ and front finger of $M_2$.

If we denote function $front(T)$ returns the front finger, $rear(T)$ returns the rear finger,
$mid(T)$ returns the middle part inner tree. the above $merge()$ algorithm can be
$mid(T)$ returns the middle part inner tree. the above $merge$ algorithm can be
expressed for non-trivial case as the following.

\be
Expand All @@ -2162,7 +2162,7 @@ \subsection{concatenate}
If we look back to the original concatenate solution, it can be expressed as below.

\be
concat(T_1, T_2) = tree(F_1, merge(M_1, R_1 \cup R_2, M_2), R_2)
concat(T_1, T_2) = tree(F_1, merge(M_1, R_1 \cup F_2, M_2), R_2)
\ee

And compare it with equation \ref{eq:merge-recursion}, it's easy to note the fact that
Expand Down Expand Up @@ -2220,16 +2220,16 @@ \subsection{concatenate}
If either one of the tree is a leaf, we can insert or append the element of this leaf to
$S$, so that it becomes the trivial case of concatenating one empty tree with another.

Function $nodes()$ is used to wrap a list of elements to a list of 2-3 trees.
Function $nodes$ is used to wrap a list of elements to a list of 2-3 trees.
This is because the contents of middle part inner tree, compare to the
contents of finger, are one level deeper in terms of $Node()$. Consider the
contents of finger, are one level deeper in terms of $Node$. Consider the
time point that transforms from recursive case to edge case. Let's suppose
$M_1$ is empty at that time, we then need repeatedly insert all elements from
$R_1 \cup S \cup F_2$ to $M_2$. However, we can't directly do the insertion.
If the element type is $a$, we can only insert $Node(a)$ which is 2-3 tree
to $M_2$. This is just like what we did in the $insertT()$ algorithm,
to $M_2$. This is just like what we did in the $insertT$ algorithm,
take out the last 3 elements, wrap them in a 2-3 tree, and recursive
perform $insertT()$. Here is the definition of $nodes()$.
perform $insertT$. Here is the definition of $nodes$.

\be
nodes(L) = \left \{
Expand All @@ -2243,19 +2243,19 @@ \subsection{concatenate}
\right .
\ee

Function $nodes()$ follows the constraint of 2-3 tree, that if there are
Function $nodes$ follows the constraint of 2-3 tree, that if there are
only 2 or 3 elements in the list, it just wrap them in singleton list
contains a 2-3 tree; If there are 4 elements in the lists, it split them
into two trees each is consist of 2 branches; Otherwise, if there are
more elements than 4, it wraps the first three in to one tree with 3 branches,
and recursively call $nodes()$ to process the rest.
and recursively call $nodes$ to process the rest.

The performance of concatenation is determined by merging. Analyze the
recursive case of merging reveals that the depth of recursion is
proportion to the smaller height of the two trees. As the tree is
ensured to be balanced by using 2-3 tree. it's height is bound to
$O(\lg n')$ where $n'$ is the number of elements. The edge
case of merging performs as same as insertion, (It calls $insertT()$
case of merging performs as same as insertion, (It calls $insertT$
at most 8 times) which is amortized $O(1)$ time, and $O(\lg m)$
at worst case, where $m$ is the difference in height of the two trees.
So the overall performance is bound to $O(\lg n)$, where $n$ is
Expand All @@ -2281,7 +2281,7 @@ \subsection{concatenate}
merge (Tr f1 m1 r1) ts (Tr f2 m2 r2) = Tr f1 (merge m1 (nodes (r1 ++ ts ++ f2)) m2) r2
\end{lstlisting}

And the implementation of $nodes()$ is as below.
And the implementation of $nodes$ is as below.

\begin{lstlisting}
nodes :: [a] -> [Node a]
Expand Down Expand Up @@ -2661,7 +2661,7 @@ \subsubsection{size augmentation}
\subsubsection{Modification due to the augmented size}

The algorithms have been presented so far need to be modified to accomplish with the
augmented size. For example the $insertT()$ function now inserts a tree node instead
augmented size. For example the $insertT$ function now inserts a tree node instead
of a plain element.

\be
Expand Down Expand Up @@ -2806,12 +2806,12 @@ \subsubsection{Modification due to the augmented size}
\end{lstlisting}

Note that the tree constructor is also modified to take a size argument
as the first parameter. And the \texttt{leaf()} helper function does not
as the first parameter. And the \texttt{leaf} helper function does not
only construct the tree from a node, but also set the size of the tree
with the same size of the node inside it.

For simplification purpose, we skip the detailed description of what are modified in
$extractT()$, $appendT()$, $removeT()$, and $concat()$ algorithms. They are left as exercises to the
$extractT$, $appendT$, $removeT$, and $concat$ algorithms. They are left as exercises to the
reader.

\subsubsection{Split a finger tree at a given position}
Expand Down

0 comments on commit e1c7eef

Please sign in to comment.