Skip to content

Commit

Permalink
Merge branch 'master' of G:\gitroot\writing into algoxy
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinyu95 committed Apr 21, 2011
2 parents 9882a16 + 2b27f9c commit 85d383f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ SRC = common-en.tex

all: $(BOOK).pdf

index:
makeindex $(BOOK)

$(BOOK).pdf: $(SRC)
latex $(BOOK).tex
makeindex -o $(BOOK).ind $(BOOK).idx #must have \makeindex in tex file
makeindex $(BOOK).idx
latex $(BOOK).tex
dvipdfmx $(BOOK)

Expand All @@ -15,5 +18,3 @@ clean:
distclean: clean
rm -f *.pdf *.dvi *~



1 change: 1 addition & 0 deletions common-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
%\usepackage{algorithmic} %old version; we can use algorithmicx instead
\usepackage{algorithm}
\usepackage[noend]{algpseudocode} %for pseudo code, include algorithmicsx automatically
\usepackage{makeidx} % for index support


\lstdefinelanguage{Smalltalk}{
Expand Down
16 changes: 14 additions & 2 deletions datastruct/tree/binary-search-tree/bstree-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ \chapter{Binary search tree, the `hello world' data structure}
% Introduction
% ================================================================
\section{Introduction}
\label{introduction}
\label{introduction} \index{binary search tree}

It's typically considered that Arrays or Lists are the `hello world' data structure.
However, we'll see they are not so easy to implement actually. In some procedural
Expand All @@ -53,7 +53,7 @@ \section{Introduction}
Considering these factors, we start with Binary Search Tree (or BST) as the `hello world'
data structure. Jon Bentley mentioned an interesting problem in `programming pearls'
\cite{Bentley}. The problem is about to count the number of times each word occurs
in a big text. And the solution is something like the below C++ code.
in a big text. And the solution is something like the below C++ code.\index{word counter}

\lstset{language=C++}
\begin{lstlisting}
Expand Down Expand Up @@ -88,6 +88,7 @@ \section{Introduction}

The concept of Binary tree is a recursive definition. Binary search tree is just a special
type of binary tree. The Binary tree is typically defined as the following.
\index{binary tree}

A binary tree is
\begin{itemize}
Expand Down Expand Up @@ -129,6 +130,7 @@ \section{Introduction}
% Data layout
% ================================================================
\section{Data Layout}
\index{binary search tree!data layout}

Based on the recursive definition of binary search tree, we can draw the
data layout in procedural setting with pointer supported as in figure
Expand Down Expand Up @@ -205,6 +207,7 @@ \section{Data Layout}
% Insert
% ================================================================
\section{Insertion}
\index{binary search tree!insertion}

To insert a key $k$ (may be along with a value in practice) to a binary search tree $T$, we can follow a quite straight forward way.

Expand Down Expand Up @@ -318,6 +321,7 @@ \section{Insertion}
post for reference.

\section{Traversing}
\index{binary search tree!traverse}

Traversing means visiting every element one by one in a binary
search tree. There are 3 ways to traverse a binary tree, pre-order tree walk,
Expand All @@ -336,6 +340,8 @@ \section{Traversing}
\item post-order traverse, visit $left$, then $right$, finally $current$.
\end{itemize}

\index{pre-order traverse} \index{in-order traverse} \index{post-order traverse}

Note that each visiting operation is recursive. And we see the order
of visiting $current$ determines the name of the traversing method.

Expand Down Expand Up @@ -492,6 +498,8 @@ \subsection*{Exercise}
% Querying a binary search tree
% ================================================================
\section{Querying a binary search tree}
\index{binary search tree!search}
\index{binary search tree!looking up}

There are three types of querying for binary search tree, searching
a key in the tree, find the minimum or maximum element in the tree,
Expand Down Expand Up @@ -577,6 +585,7 @@ \subsection{Looking up}
\end{lstlisting}

\subsection{Minimum and maximum}
\index{binary search tree!min/max}

Minimum and maximum can be implemented from the property of binary search
tree, less keys are always in left child, and greater keys are in right.
Expand Down Expand Up @@ -612,6 +621,7 @@ \subsection{Minimum and maximum}
in pure procedural way without using recursion.

\subsection{Successor and predecessor}
\index{binary search tree!succ/pred}

The last kind of querying, to find the successor or predecessor of an element
is useful when a tree is treated as a generic container and traversed by
Expand Down Expand Up @@ -723,6 +733,7 @@ \subsection*{Exercise}
% Deletion
% ================================================================
\section{Deletion}
\index{binary search tree!delete}
Deletion is another `imperative only' topic for binary search tree.
This is because deletion mutate the tree, while in purely functional
settings, we don't modify the tree after building it in most
Expand Down Expand Up @@ -937,6 +948,7 @@ \subsection*{Exercise}
\end{itemize}

\section{Randomly build binary search tree}
\index{binary search tree!randomly build}
It can be found that all operations given in this post bound to $O(h)$
time for a tree of height $h$. The height affects the performance
a lot. For a very unbalanced tree, $h$ tends to be $O(N)$, which leads
Expand Down
7 changes: 6 additions & 1 deletion main-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@
% ================================================================
% Content
% ================================================================
\input{others/preface/preface-en.tex}

%\newpage
\tableofcontents
\newpage

\part{Introduction}
\input{others/preface/preface-en.tex}

\part{Binary search tree}
\input{datastruct/tree/binary-search-tree/bstree-en.tex}

Expand All @@ -76,4 +79,6 @@ \part{Binary heaps}
\part{GNU Free Documentation License}
\input{fdl-1.3.tex}

\printindex

\end{document}

0 comments on commit 85d383f

Please sign in to comment.