| 1 |
% This is tree_doc.tex, the documentation for the treetex macro package |
| 2 |
% as it will appear in the conference proceedings of the third European |
| 3 |
% TeX meeting in Exeter, England, 1988. |
| 4 |
|
| 5 |
\documentstyle[12pt,DIN-A4]{article} |
| 6 |
|
| 7 |
\advance\voffset by -2cm |
| 8 |
|
| 9 |
\clubpenalty=10000 |
| 10 |
\widowpenalty=10000 |
| 11 |
\def\addcontentsline#1#2#3{\relax}% Some captions are too long for some |
| 12 |
% TeX installations (buffer size too small) |
| 13 |
|
| 14 |
|
| 15 |
\newenvironment{lemma}{\begingroup\samepage\begin{lemmma}\ }{\end{lemmma}% |
| 16 |
\endgroup} |
| 17 |
\newtheorem{lemmma}{Lemma}[section] |
| 18 |
\newenvironment{proof}{\begin{prooof}\rm\ \nopagebreak}{\end{prooof}} |
| 19 |
\newcommand{\proofend}{\qquad\ifmmode\Box\else$\Box$\fi} |
| 20 |
\newtheorem{prooof}{Proof} |
| 21 |
\renewcommand{\theprooof}{} % makes shure that prooof doesn't get numbers |
| 22 |
\newenvironment{Figure}{\begin{figure}\vspace{1\baselineskip}}% |
| 23 |
{\vspace{1\baselineskip}\end{figure}} |
| 24 |
\newlength{\figspace} % space between figures in a single |
| 25 |
\setlength{\figspace}{30pt} % Figure environment |
| 26 |
|
| 27 |
\newcommand{\var}[1]{{\it #1\/}} % use it for names of variables |
| 28 |
\newcommand{\emph}[1]{{\em #1\/}} % use it for emphazided text |
| 29 |
% (This notion sticks to the |
| 30 |
% applicative style of markup.) |
| 31 |
\renewcommand{\O}{{\rm O}} % O-notation, also for math mode |
| 32 |
\newcommand{\T}{{\cal T}} % the set T in math mode |
| 33 |
\newcommand{\TreeTeX}{Tree\TeX} |
| 34 |
\newcommand{\fig}[1]{Figure~\ref{#1}} |
| 35 |
\let\p\par |
| 36 |
|
| 37 |
\input TreeTeX |
| 38 |
\Treestyle{\vdist{20pt}\minsep{16pt}} |
| 39 |
\dummyhalfcenterdim@n=2pt |
| 40 |
|
| 41 |
\def\Node(#1,#2){\put(#1,#2){\circle*{4}}} |
| 42 |
\def\Edge(#1,#2,#3,#4,#5){\put(#1,#2){\line(#3,#4){#5}}} |
| 43 |
|
| 44 |
\def\enode{\node{\external\type{dot}}} |
| 45 |
\def\inode{\node{\type{dot}}} |
| 46 |
|
| 47 |
\def\e{\node{\external\type{dot}}} |
| 48 |
\def\i{\node{\type{dot}}} |
| 49 |
\def\il{\node{\type{dot}\leftonly}} |
| 50 |
\def\ir{\node{\type{dot}\rightonly}} |
| 51 |
|
| 52 |
\newcommand{\stack}[3]{% |
| 53 |
\vtop{\settowidth{\hsize}{#1}% |
| 54 |
\setlength{\leftskip}{0pt plus 1fill}% |
| 55 |
\setlength{\baselineskip}{#2}#3}} |
| 56 |
|
| 57 |
\let\multic\multicolumn |
| 58 |
|
| 59 |
\newlength{\hd} % hidden digit |
| 60 |
\setbox0\hbox{1} |
| 61 |
\settowidth{\hd}{\usebox{0}} |
| 62 |
\newcommand{\ds}{\hspace{\hd}} % digit space |
| 63 |
|
| 64 |
\newcommand{\ccol}[1]{\multicolumn{1}{c}{#1}} |
| 65 |
|
| 66 |
\hyphenation{post-or-der sym-bol Karls-ruhe bool-ean} |
| 67 |
|
| 68 |
\begin{document} |
| 69 |
|
| 70 |
\bibliographystyle{plain} |
| 71 |
|
| 72 |
\title{Drawing Trees Nicely with \TeX\thanks{This work was supported by |
| 73 |
a Natural Sciences and Engineering Research Council of Canada |
| 74 |
Grant~A-5692 and a Deutsche Forschungsgemeinschaft Grant~Sto167/1-1. |
| 75 |
It was started during the first author's stay with |
| 76 |
the Data Structuring Group in Waterloo.}} |
| 77 |
\author{Anne Br\"uggemann-Klein\thanks{Institut f\"ur Informatik, |
| 78 |
Universit\"at Freiburg, Rheinstr.~10--12, 7800~Freiburg, |
| 79 |
West~Germany}\ \and Derick Wood\thanks{Data |
| 80 |
Structuring Group, Department of Computer Science, University of |
| 81 |
Waterloo, Waterloo, Ontario, N2L~3G1, Canada}} |
| 82 |
\maketitle |
| 83 |
|
| 84 |
\begin{abstract} |
| 85 |
|
| 86 |
Various algorithms have been proposed for the difficult problem of |
| 87 |
producing aesthetically pleasing drawings of trees, see~% |
| 88 |
\cite{TidierTrees,TidyTrees} but |
| 89 |
implementations only exist as ``special purpose software'', |
| 90 |
designed for special environments. Therefore, |
| 91 |
many users resort to the |
| 92 |
drawing facilities available on most personal computers, but the |
| 93 |
figures obtained in this way still look ``hand-drawn''; their quality is |
| 94 |
inferior to the quality of the surrounding text that can be realized by |
| 95 |
today's high quality text processing systems. |
| 96 |
|
| 97 |
In this paper we present an entirely new solution that |
| 98 |
integrates a tree drawing algorithm into one of the best text |
| 99 |
processing systems available. More precisely, we present a \TeX{} macro package |
| 100 |
\TreeTeX{} that produces a drawing of a tree from a purely logical |
| 101 |
description. Our approach has three advantages. First, labels |
| 102 |
for nodes can be handled in a reasonable way. On the one hand, the tree |
| 103 |
drawing algorithm can compute the widths of the labels and take |
| 104 |
them into account for the positioning of the nodes; on the other hand, |
| 105 |
all the textual parts of the document can be treated uniformly. Second, |
| 106 |
\TreeTeX{} can be trivially ported to any site running \TeX{}. Finally, |
| 107 |
modularity in the description of a tree and \TeX{}'s macro capabilities |
| 108 |
allow for libraries of subtrees and tree classes. |
| 109 |
|
| 110 |
In addition, we have implemented an option that produces |
| 111 |
drawings which make the |
| 112 |
\emph{structure} of the trees more obvious to the human eye, |
| 113 |
even though they may not be as aesthetically pleasing. |
| 114 |
|
| 115 |
\end{abstract} |
| 116 |
|
| 117 |
\section{Aesthetical criteria for drawing trees} |
| 118 |
|
| 119 |
One of the most commonly used data structures in computer science is the tree. |
| 120 |
As many people are using trees in their research or just as illustration |
| 121 |
tools, they are usually struggling with the problem of |
| 122 |
\emph{drawing} trees. We are concerned primarily with ordered |
| 123 |
trees in the sense of~\cite{ACP}, especially binary and unary-binary |
| 124 |
trees. A binary tree is a finite set of nodes which either |
| 125 |
is empty, or consists of a root and two disjoint binary trees called |
| 126 |
the left and right subtrees of the root. A unary-binary tree is |
| 127 |
a finite set of nodes which either is empty, or consists of a root and |
| 128 |
two disjoint unary-binary trees, or consists of a root and one |
| 129 |
nonempty unary-binary tree. An extended binary tree is a binary tree |
| 130 |
in which each node has either two nonempty subtrees or two |
| 131 |
empty subtrees. |
| 132 |
|
| 133 |
For these trees there |
| 134 |
are some basic agreements on how they should be drawn, reflecting |
| 135 |
the top-down and left-right ordering of nodes in a tree; |
| 136 |
see \cite{TidierTrees} and \cite{TidyTrees}. |
| 137 |
|
| 138 |
\begin{enumerate} |
| 139 |
\item[1.] Trees impose a distance on the nodes; no node |
| 140 |
should be closer to the root than any of its |
| 141 |
ancestors. |
| 142 |
\item[2.] Nodes of a tree at the same height should lie on a straight |
| 143 |
line, and the straight lines defining the levels should be |
| 144 |
parallel. |
| 145 |
\item[3.] The relative order of nodes on any level should be the same |
| 146 |
as in the level order traversal of the tree. |
| 147 |
\end{enumerate} |
| 148 |
|
| 149 |
These axioms guarantee that trees are drawn as planar graphs: edges do |
| 150 |
not intersect except at nodes. Two further axioms improve the aesthetical |
| 151 |
appearance of trees: |
| 152 |
|
| 153 |
\begin{enumerate} |
| 154 |
\item[4.] In a unary-binary tree, each left child should be positioned |
| 155 |
to the left of its parent, each |
| 156 |
right child to the right of its parent, and each unary child |
| 157 |
should be positioned below its parent. |
| 158 |
\item[5.] A parent should be centered over its children. |
| 159 |
\end{enumerate} |
| 160 |
|
| 161 |
An additional axiom deals with the problem of tree drawings becoming too wide |
| 162 |
and therefore exceeding the physical limit of the output medium: |
| 163 |
|
| 164 |
\begin{enumerate} |
| 165 |
\item[6.] Tree drawings should occupy as little width as possible without |
| 166 |
violating the other axioms. |
| 167 |
\end{enumerate} |
| 168 |
|
| 169 |
In \cite{TidyTrees}, Wetherell and Shannon introduce two algorithms for |
| 170 |
tree drawings, the first of which fulfills axioms~1--5, and the second |
| 171 |
1--6. However, as Reingold and Tilford in \cite{TidierTrees} |
| 172 |
point out, there is a lack of symmetry in the algorithms of |
| 173 |
Wetherell and Shannon which may lead to unpleasant results. |
| 174 |
Therefore, Reingold and Tilford introduce a new structured |
| 175 |
axiom: |
| 176 |
|
| 177 |
\begin{enumerate} |
| 178 |
\item[7.] A subtree of a given tree should be |
| 179 |
drawn the same way regardless of where it occurs in the given tree. |
| 180 |
\end{enumerate} |
| 181 |
|
| 182 |
Axiom~7 allows the same tree to be drawn differently when it occurs as |
| 183 |
a subtree in different trees. |
| 184 |
Reingold and Tilford give an algorithm which fulfills axioms~1--5 |
| 185 |
and~7. Although |
| 186 |
this algorithm doesn't fulfill axiom~6, |
| 187 |
the aesthetical improvements are well worth the additional space. |
| 188 |
\fig{algorithms} illustrates the benefits of axiom~7, and \fig{narrowtrees} |
| 189 |
shows that the algorithm of Reingold and Tilford violates axiom~6. |
| 190 |
|
| 191 |
\begin{Figure} |
| 192 |
\centering |
| 193 |
\leavevmode\noindent |
| 194 |
\begin{Tree} |
| 195 |
\enode |
| 196 |
\enode\enode\inode\enode\enode\inode\inode\inode |
| 197 |
\node{\external\type{dot}\rght{\unskip\hskip2\mins@p\hskip2\dotw@dth}} |
| 198 |
\enode\enode\inode\enode\enode\inode\inode\inode |
| 199 |
\inode |
| 200 |
\end{Tree} |
| 201 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 202 |
\begin{Tree} |
| 203 |
\enode |
| 204 |
\enode\enode\inode\enode\enode\inode\inode\inode |
| 205 |
\enode |
| 206 |
\enode\enode\inode\enode\enode\inode\inode\inode |
| 207 |
\inode |
| 208 |
\end{Tree} |
| 209 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\ |
| 210 |
\caption{The left tree is drawn by the algorithm of Wetherell and Shannon, |
| 211 |
and the tidier right one is drawn by the algorithm of Reingold and Tilford.} |
| 212 |
\label{algorithms} |
| 213 |
|
| 214 |
\vspace{\figspace} |
| 215 |
\centering |
| 216 |
\leavevmode\noindent |
| 217 |
\begin{Tree} |
| 218 |
\enode\enode\enode\enode\enode\enode\enode\enode\enode |
| 219 |
\enode\inode\inode\inode |
| 220 |
\enode\inode\inode\inode |
| 221 |
\enode\inode\inode\inode |
| 222 |
\enode\inode\inode\inode |
| 223 |
\end{Tree} |
| 224 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 225 |
\begin{Tree} |
| 226 |
\enode\enode\enode\enode\enode\enode\enode\enode |
| 227 |
\node{\external\type{dot}\rght{\unskip\hskip\mins@p\hskip\dotw@dth}} |
| 228 |
\enode\inode\inode\node{\type{dot}\rght{\unskip\hskip\mins@p\hskip\dotw@dth}} |
| 229 |
\enode\inode\inode\node{\type{dot}\rght{\unskip\hskip\mins@p\hskip\dotw@dth}} |
| 230 |
\enode\inode\inode\node{\type{dot}\rght{\unskip\hskip\mins@p\hskip\dotw@dth}} |
| 231 |
\enode\inode\inode\inode |
| 232 |
\end{Tree} |
| 233 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\ |
| 234 |
\caption{The left tree is drawn by the algorithm of Reingold and Tildford, but |
| 235 |
the right tree shows that narrower drawings fulfilling all aesthetic axioms |
| 236 |
are possible.} |
| 237 |
\label{narrowtrees} |
| 238 |
\end{Figure} |
| 239 |
|
| 240 |
|
| 241 |
\section{The algorithm of Reingold and Tilford} |
| 242 |
|
| 243 |
The algorithm of Reingold and Tilford (hereafter called ``the RT~algorithm'') |
| 244 |
takes a modular approach to the |
| 245 |
positioning of nodes: The relative positions of the nodes in a subtree |
| 246 |
are calculated independently from the rest of the tree. After the |
| 247 |
relative positions of two subtrees have been calculated, they can be |
| 248 |
joined as siblings in a larger tree by placing them as close |
| 249 |
together as possible and centering the parent node above them. |
| 250 |
Incidentally, the modularity principle is the reason that the |
| 251 |
algorithm fails to fulfill axiom~6; see~\cite{Complexity}. |
| 252 |
Two sibling subtrees are placed as close together as possible, |
| 253 |
during a postorder traversal, as follows. At each node \var{T}, |
| 254 |
imagine that its two subtrees have been drawn and cut out of paper along |
| 255 |
their contours. Then, starting with the two subtrees superimposed at their |
| 256 |
roots, move them apart until a minimal agreed upon distance |
| 257 |
between the trees is obtained at each level. This can be done gradually: |
| 258 |
Initially, their roots are separated by some agreed upon minimum |
| 259 |
distance. Then, at the next lower level, |
| 260 |
they are pushed |
| 261 |
apart until the minimum separation is established there. |
| 262 |
This process is continued at successively lower levels until the |
| 263 |
bottom of the shorter subtree is reached. At some levels no movement may be |
| 264 |
necessary; but at no level are the two subtrees moved closer |
| 265 |
together. When the process is complete, the position of the |
| 266 |
subtrees is fixed relative to their parent, which is centered over them. |
| 267 |
Assured that the subtrees will never be placed closer together, |
| 268 |
the postorder traversal is continued. |
| 269 |
|
| 270 |
A nontrivial implementation of |
| 271 |
this algorithm has been obtained by Reingold and Tilford that runs |
| 272 |
in time $\O(N)$, where $N$ is the number of |
| 273 |
nodes of the tree to be drawn. |
| 274 |
Their crucial idea is to keep track of the contour of the subtrees |
| 275 |
by special pointers, called threads, such that whenever |
| 276 |
two subtrees are joined, only the |
| 277 |
top part of the trees down to the lowest level of the |
| 278 |
smaller tree need to be taken into account. |
| 279 |
|
| 280 |
The RT algorithm is given in \cite{TidierTrees}. |
| 281 |
The nodes are positioned on a fixed grid and are |
| 282 |
considered to have zero width. No labelling is provided. The algorithm only |
| 283 |
draws binary trees, but is easily extendable to multiway trees. |
| 284 |
|
| 285 |
\section{Improving human perception of trees} |
| 286 |
|
| 287 |
It is common understanding in book design that aesthetics and readability |
| 288 |
don't necessarily coincide, and---as Lamport (\cite{LaTeX}) puts it---% |
| 289 |
books are meant to be read, not to be hung on walls. Therefore, readability is |
| 290 |
more important than aesthetics. |
| 291 |
|
| 292 |
When it comes to tree drawings, readability means that the structure of |
| 293 |
a tree must be easily recognizable. This criterion is not always met |
| 294 |
by the RT~algorithm. As an example, there are trees whose structure is very |
| 295 |
different, the only common thing being the fact that they have the same number |
| 296 |
of nodes at each level. The RT~algorithm might assign identical positions to |
| 297 |
these nodes making it very hard to perceive the different structures. |
| 298 |
Hence, we have modified the RT~algorithm such that additional white space |
| 299 |
is inserted between subtrees of |
| 300 |
\emph{significant} nodes. Here a binary node |
| 301 |
is called significant if the minimum distance |
| 302 |
between its two subtrees is taken \emph{below} their root level. |
| 303 |
Setting the amount of additional white space to zero retains the original RT~% |
| 304 |
placement. The effect of having nonzero additional white space between |
| 305 |
the subtrees of significant |
| 306 |
nodes is illustrated in \fig{addspace} . |
| 307 |
|
| 308 |
Another feature we have added to the RT~algorithms is the possibility to draw |
| 309 |
an unextended binary tree with the same placement of nodes as its |
| 310 |
associated extended version. We define the \emph{associated extended version} |
| 311 |
of a binary tree to be the binary tree obtained by replacing each empty subtree |
| 312 |
having a nonempty sibling with a subtree consisting of one node. This feature |
| 313 |
also makes the structure of a tree more prominent; see \fig{extended}. |
| 314 |
|
| 315 |
\begin{Figure} |
| 316 |
\centering |
| 317 |
\leavevmode\noindent |
| 318 |
\begin{Tree} |
| 319 |
\e\il\e\e\i\i\il % the left subtree |
| 320 |
\e\ir\il % the right subtree |
| 321 |
\i |
| 322 |
\end{Tree} |
| 323 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 324 |
\begin{Tree} |
| 325 |
\e\il\il\il % the left subtree |
| 326 |
\e\e\i\e\i\il % the right subtree |
| 327 |
\i |
| 328 |
\end{Tree} |
| 329 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 330 |
\adds@p10pt |
| 331 |
\begin{Tree} |
| 332 |
\e\il\e\e\i\node{\type{dot}\lft{$\longrightarrow$}}\il % the left subtree |
| 333 |
\e\ir\il % the right subtree |
| 334 |
\node{\type{dot}\lft{$\longrightarrow$}} |
| 335 |
\end{Tree} |
| 336 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 337 |
\begin{Tree} |
| 338 |
\e\il\il\il % the left subtree |
| 339 |
\e\e\i\e\i\il % the right subtree |
| 340 |
\node{\type{dot}\lft{$\longrightarrow$}} |
| 341 |
\end{Tree} |
| 342 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\ |
| 343 |
\adds@p0pt |
| 344 |
|
| 345 |
\caption{The first two trees get the same placement of their nodes |
| 346 |
by the RT~algorithm, although the structure of the two trees is very different. |
| 347 |
The alternative drawings highlight the structure of the trees by adding |
| 348 |
additional white space between the subtrees of |
| 349 |
($\longrightarrow$) significant nodes.} |
| 350 |
\label{addspace} |
| 351 |
\end{Figure} |
| 352 |
|
| 353 |
\begin{Figure} |
| 354 |
\centering |
| 355 |
\leavevmode\noindent |
| 356 |
\begin{Tree} |
| 357 |
\e\e\i\il\e\e\i\i |
| 358 |
\end{Tree} |
| 359 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 360 |
\begin{Tree} |
| 361 |
\e\e\i\e\i\e\ir\i |
| 362 |
\end{Tree} |
| 363 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 364 |
\extended |
| 365 |
\begin{Tree} |
| 366 |
\e\e\i\il\e\e\i\i |
| 367 |
\end{Tree} |
| 368 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\qquad |
| 369 |
\begin{Tree} |
| 370 |
\e\e\i\e\i\e\ir\i |
| 371 |
\end{Tree} |
| 372 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\\ |
| 373 |
\noextended |
| 374 |
\begin{Tree} |
| 375 |
\e\e\i\e\i\e\e\i\i |
| 376 |
\end{Tree} |
| 377 |
\hskip\leftdist\box\TeXTree\hskip\rightdist\ |
| 378 |
\caption{In the first two drawings, the RT~algorithm assigns the same placement |
| 379 |
to the nodes of two trees although their structure is very different. The modified |
| 380 |
RT~algorithms highlights the structure of the trees by optionally |
| 381 |
drawing them like their extended |
| 382 |
counterpart, which is given in the second row.} |
| 383 |
\label{extended} |
| 384 |
\end{Figure} |
| 385 |
|
| 386 |
|
| 387 |
\section{Trees in a document preparation environment} |
| 388 |
|
| 389 |
Drawings of trees usually don't come alone, but are included in some text |
| 390 |
which is itself typeset by a text processing system. Therefore, a typical |
| 391 |
scenario is a pipe of three stages. First comes the tree drawing |
| 392 |
program which calculates the positioning of the nodes of the tree to |
| 393 |
be drawn and outputs a description of the tree drawing in |
| 394 |
some graphics language; next comes a graphics system which transforms this |
| 395 |
description into an intermediate language which can be interpreted by the output |
| 396 |
device; and finally comes the |
| 397 |
text processing system which integrates the output of the |
| 398 |
graphics system into the text. |
| 399 |
|
| 400 |
This scenario loses its linear structure once nodes have to be labelled, since |
| 401 |
the labelling influences the positioning of the nodes. Labels usually occur |
| 402 |
inside, to the left of, to the right of, or beneath nodes (the latter only for |
| 403 |
external nodes), and their extensions certainly should be taken into account |
| 404 |
by the tree drawing algorithm. But the labels have to be typeset first |
| 405 |
in order to determine their extensions, |
| 406 |
preferably by the typesetting program that |
| 407 |
is used for the regular text, because this method makes for the uniformity in the textual |
| 408 |
parts of the document and provides the author with the full power of the |
| 409 |
text processing system for composing the labels. Hence, a more complex |
| 410 |
communication scheme than a simple pipe is required. |
| 411 |
|
| 412 |
Although a system of two processes running simultaneously might be the most |
| 413 |
elegant solution, we wanted a system that is easily portable to |
| 414 |
a large range of hardware at our sites |
| 415 |
including personal computers with single process |
| 416 |
operating systems. |
| 417 |
Therefore, we thought of using a text processing system |
| 418 |
having programming facilities powerful enough to program a tree drawing algorithm |
| 419 |
and graphics facilities powerful enough |
| 420 |
to draw a tree. One text processing system |
| 421 |
rendering outstanding typographic quality and good enough programming |
| 422 |
facilities is \TeX, developed by Knuth at Stanford University; |
| 423 |
see~\cite{TeXbook}. |
| 424 |
The \TeX{} system includes the following programming facilities: |
| 425 |
|
| 426 |
\begin{enumerate} |
| 427 |
\item[1.] datatypes:\\ |
| 428 |
integers~(256), dimensions\footnote{The term \emph{dimension} is used |
| 429 |
in \TeX\ to describe physical measurements of typographical objects, |
| 430 |
like the length of a word.}~(512), boxes~(256), tokenlists~(256), boolean |
| 431 |
variables~(unrestricted) |
| 432 |
\item[2.] elementary statements:\\ |
| 433 |
$a:=\rm const$, $a:=b$ (all types);\\ |
| 434 |
$a:=a+b$, $a:=a*b$, $a:=a/b$ (integers and dimensions);\\ |
| 435 |
horizontal and vertical nesting of boxes |
| 436 |
\item[3.] control constructs:\\ |
| 437 |
if-then-else statements testing relations between integers, |
| 438 |
dimensions, boxes, or boolean variables |
| 439 |
\item[4.] modularization constructs:\\ |
| 440 |
macros with up to 9~parameters (can be viewed as procedures without |
| 441 |
the concept of local variables). |
| 442 |
\end{enumerate} |
| 443 |
|
| 444 |
Although the programming |
| 445 |
facilities of \TeX{} hardly exceed the abilities of a Turing machine, |
| 446 |
they are sufficient to |
| 447 |
handle relatively small programs. How about the graphics facilities? |
| 448 |
Although \TeX{} has no built-in graphics facilities, it |
| 449 |
allows the placement of characters in arbitrary positions on |
| 450 |
the page. Therefore, complex pictures can be synthesized from elementary |
| 451 |
picture elements treated as characters. Lamport has included such |
| 452 |
a picture drawing environment in his macro package \LaTeX, using |
| 453 |
quarter circles of different sizes and line segments (with and without |
| 454 |
arrow heads) of different slopes as basic elements; see~\cite{LaTeX}. |
| 455 |
These elements are sufficient for drawing trees. |
| 456 |
|
| 457 |
This survey of \TeX's capabilities implies that \TeX{} may be a suitable |
| 458 |
text processing system to implement a tree drawing algorithm directly. |
| 459 |
We are basing our algorithm on the RT~algorithm, because this algorithm |
| 460 |
gives the aesthetically most pleasing results. In the first version |
| 461 |
presented here, we |
| 462 |
restrict ourselves to unary-binary trees, although our method is |
| 463 |
applicable to arbitrary multiway trees. But in order to take advantage |
| 464 |
of the text processing environment, we expand the algorithm to allow |
| 465 |
labelled nodes. |
| 466 |
|
| 467 |
In contrast to previous tree drawing programs, we feel no necessity to |
| 468 |
position the nodes of a tree on a fixed grid. While this may be |
| 469 |
reasonable for a plotter with a coarse resolution, it is certainly not |
| 470 |
necessary for \TeX, a system that is capable of handling |
| 471 |
arbitrary dimensions |
| 472 |
and produces device \emph{independent} output. |
| 473 |
|
| 474 |
|
| 475 |
\section{A representation method for \TeX{}trees} |
| 476 |
|
| 477 |
The first problem to be solved in implementing our tree drawing algorithm |
| 478 |
is how to choose a good internal representation |
| 479 |
for trees. A straightforward adaptation |
| 480 |
of the implementation by Reingold and Tilford requires, for each node, |
| 481 |
at least the following fields: |
| 482 |
|
| 483 |
\begin{enumerate} |
| 484 |
\item two pointers to the children of the node |
| 485 |
\item two dimensions for the offset to the left and the right child (these |
| 486 |
may be different once there are labels of different widths to the |
| 487 |
left and right of the nodes) |
| 488 |
\item two dimensions for the $x$- and $y$-coordinates of the final |
| 489 |
position of the nodes |
| 490 |
\item three or four labels |
| 491 |
\item one token to store the geometric shape (circle, square, framed text etc.) |
| 492 |
of the node. |
| 493 |
\end{enumerate} |
| 494 |
|
| 495 |
Because these data are used very frequently in calculations, they should be |
| 496 |
stored in registers (that's what variables are called in \TeX), |
| 497 |
rather than being recomputed, in order to obtain |
| 498 |
reasonably fast performance. This gives a total of $10N$ registers for |
| 499 |
a tree with $N$ nodes, which would exceed |
| 500 |
\TeX's limited supply of registers. Therefore, we present a |
| 501 |
modified algorithm hand-tailored to the abilities of \TeX{}. |
| 502 |
We start with the following observation. |
| 503 |
Suppose a unary-binary tree is constructed bottom-up, in a postorder |
| 504 |
traversal. This is done by iterating the following three steps in |
| 505 |
an order determined by the tree to be constructed. |
| 506 |
|
| 507 |
\begin{enumerate} |
| 508 |
\item Create a new subtree consisting of one external node. |
| 509 |
\item Create a new subtree by appending the two subtrees created last |
| 510 |
to a new binary node; see \fig{Construct}. |
| 511 |
\item Create a new subtree by appending the subtree created last as a left, |
| 512 |
right, or unary subtree of a new node; see \fig{Construct}. |
| 513 |
\end{enumerate} |
| 514 |
|
| 515 |
(A pointer to) each subtree that has been |
| 516 |
created in steps 1--3 is pushed onto a stack, and |
| 517 |
steps 2 and 3 remove two trees or one, respectively, |
| 518 |
from the stack before the push |
| 519 |
operation is carried out. Finally, the tree to be constructed will |
| 520 |
be the remaining tree on the |
| 521 |
stack. |
| 522 |
|
| 523 |
\begin{Figure} |
| 524 |
\centering |
| 525 |
\begin{Tree} |
| 526 |
\treesymbol{\lvls{2}}% |
| 527 |
\hspace{-\l@stlmoff}\usebox{\l@sttreebox}\hspace{\l@strmoff} |
| 528 |
$+$ |
| 529 |
\treesymbol{\lvls{2}}% |
| 530 |
\hspace{-\l@stlmoff}\usebox{\l@sttreebox}\hspace{\l@strmoff}\quad |
| 531 |
$\Longrightarrow$\quad |
| 532 |
\treesymbol{\lvls{2}}% |
| 533 |
\treesymbol{\lvls{2}}% |
| 534 |
\node{\type{dot}}% |
| 535 |
\hspace{-\l@stlmoff}\raisebox{\vd@st}{\usebox\l@sttreebox}\hspace{\l@strmoff}% |
| 536 |
\end{Tree} |
| 537 |
|
| 538 |
\vskip\baselineskip |
| 539 |
|
| 540 |
\begin{Tree} |
| 541 |
\treesymbol{\lvls{2}}% |
| 542 |
\hspace{-\l@stlmoff}\usebox{\l@sttreebox}\hspace{\l@strmoff}\quad |
| 543 |
$\Longrightarrow$\quad |
| 544 |
\treesymbol{\lvls{2}}% |
| 545 |
\node{\leftonly\type{dot}}% |
| 546 |
\hspace{-\l@stlmoff}\raisebox{\vd@st}{\usebox\l@sttreebox}\hspace{\l@strmoff}% |
| 547 |
\quad or\quad |
| 548 |
\treesymbol{\lvls{2}}% |
| 549 |
\node{\unary\type{dot}}% |
| 550 |
\hspace{-\l@stlmoff}\raisebox{\vd@st}{\usebox\l@sttreebox}\hspace{\l@strmoff}% |
| 551 |
\quad or\quad |
| 552 |
\treesymbol{\lvls{2}}% |
| 553 |
\node{\rightonly\type{dot}}% |
| 554 |
\hspace{-\l@stlmoff}\raisebox{\vd@st}{\usebox\l@sttreebox}\hspace{\l@strmoff}% |
| 555 |
\end{Tree} |
| 556 |
|
| 557 |
\caption{Construction steps 2 and 3} |
| 558 |
\label{Construct} |
| 559 |
\end{Figure} |
| 560 |
|
| 561 |
This tree traversal is performed twice in the RT~algorithm. |
| 562 |
During the first pass, |
| 563 |
at each execution of step 2 or step 3, the relative positions of the |
| 564 |
subtree(s) and of the new node are computed. |
| 565 |
A closer examination of the RT~algorithm reveals that information about the |
| 566 |
subtree's coordinates is not needed during this pass; the contour information |
| 567 |
alone would be sufficient. Complete information is only needed in the second |
| 568 |
traversal, when the tree is actually drawn. Here a special feature of |
| 569 |
\TeX{} comes in that allows us to save registers. |
| 570 |
Unlike Pascal, \TeX{} provides the capability of |
| 571 |
storing a drawing in a single box register that can be positioned freely in |
| 572 |
later drawings. This means that in our implementation the two passes |
| 573 |
of the original RT~algorithm can be intertwined into a single pass, |
| 574 |
storing for each subtree on the stack its contour and its drawing. |
| 575 |
Although the latter is a complex object, it takes only one of |
| 576 |
\TeX's precious registers. |
| 577 |
|
| 578 |
|
| 579 |
\section{The internal representation} |
| 580 |
|
| 581 |
Given a tree, the corresponding \TeX{}tree is a box containing |
| 582 |
the ``drawing'' of the tree, together with some additional |
| 583 |
information about the contour of the tree. |
| 584 |
The reference point of a \TeX{}tree-box is always in the root of the |
| 585 |
tree. The height, depth, and width of the box of a \TeX{}tree are |
| 586 |
of no importance in this context. |
| 587 |
|
| 588 |
The additional information about the contour of the tree is stored in some |
| 589 |
registers for numbers and dimensions and |
| 590 |
is needed in order to put subtrees together to form a larger tree. |
| 591 |
\var{loff} is an array of dimensions which contains for each |
| 592 |
level of the tree the horizontal offset between the |
| 593 |
left end of the |
| 594 |
leftmost node at the current level and the |
| 595 |
left end of the leftmost node at |
| 596 |
the next level. |
| 597 |
\var{lmoff} holds the horizontal offset between the root |
| 598 |
and the leftmost node of the whole tree. \var{lboff} holds the |
| 599 |
horizontal offset between the root and the leftmost node at |
| 600 |
the bottom level of the tree. |
| 601 |
Finally, \var{ltop} holds the distance between the reference point |
| 602 |
of the tree and the leftmost end of the root. |
| 603 |
The same is true for |
| 604 |
\var{roff}, \var{rmoff}, \var{rboff}, and \var{rtop}; just replace |
| 605 |
``left'' by ``right''. Finally, |
| 606 |
\var{height} holds the height of the tree, and \var{type} holds the |
| 607 |
geometric shape of the root of the tree. \fig{TeXtree} shows an example \TeX{}tree, |
| 608 |
i.e. a tree drawing and the corresponding additional information. |
| 609 |
|
| 610 |
\begin{Figure} |
| 611 |
\centering |
| 612 |
\begin{Tree} |
| 613 |
\e\ir\ir\e |
| 614 |
\node{\type{dot}\rightonly\rght{\unskip\vrule height.8pt width5pt depth0pt}}% |
| 615 |
\i % A |
| 616 |
\end{Tree} |
| 617 |
\leavevmode |
| 618 |
\stack{-10pt}{\vd@st}{% |
| 619 |
-10pt\\10pt\\10pt\\\var{loff}}% |
| 620 |
\hspace{1em}% |
| 621 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}% |
| 622 |
\hspace{1em}% |
| 623 |
\stack{-10pt}{\vd@st}{% |
| 624 |
15pt\\5pt\\-10pt\\\var{roff}}% |
| 625 |
|
| 626 |
\vskip\baselineskip\raggedright |
| 627 |
height:~3, type:~dot, ltop:~2pt, rtop:~2pt, lmoff:~-10pt, rmoff:~20pt, lboff:~10pt, |
| 628 |
rboff:~10pt. |
| 629 |
|
| 630 |
\caption{A \TeX{}tree consists of the drawing of the tree and the |
| 631 |
additional information. The width of the dots is 4pt, the minimal separation between |
| 632 |
adjacent nodes is 16pt, making for a distance of 20pt center to center. |
| 633 |
The length of the small rule labelling one of the nodes is 5pt. The column left (right) |
| 634 |
of the tree drawing is the array \var{loff} (\var{roff}), |
| 635 |
describing the left (right) contour of the tree. At each level, |
| 636 |
the dimension given is the horizontal |
| 637 |
offset between the border at the current and at the next level. The offset between |
| 638 |
the left border of the root node and the leftmost node at level~1 is -10pt, |
| 639 |
the offset between the right border of the root node and the rightmost node at |
| 640 |
level~1 is 15pt, etc.} |
| 641 |
\label{TeXtree} |
| 642 |
\end{Figure} |
| 643 |
|
| 644 |
Given two \TeX{}trees \var{A} and \var{B}, |
| 645 |
how can a new \TeX{}tree \var{C} be built that |
| 646 |
consists of a new root and has \var{A} and \var{B} as subtrees? |
| 647 |
An example is given in \fig{AddInfo}. |
| 648 |
|
| 649 |
\begin{Figure} |
| 650 |
\centering |
| 651 |
\begin{Tree} |
| 652 |
\e\ir\ir\e |
| 653 |
\node{\type{dot}\rightonly\rght{\unskip\vrule height.8pt width5pt depth0pt}}% |
| 654 |
\i % A |
| 655 |
\end{Tree} |
| 656 |
\leavevmode |
| 657 |
A: \stack{-10pt}{\vd@st}{% |
| 658 |
-10pt\\10pt\\10pt\\\ \\\var{loff}(\var{A})}% |
| 659 |
\hspace{1em}% |
| 660 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}% |
| 661 |
\hspace{1em}% |
| 662 |
\stack{-10pt}{\vd@st}{% |
| 663 |
15pt\\5pt\\-10pt\\\ \\\var{roff}(\var{A})}% |
| 664 |
\qquad |
| 665 |
\begin{Tree} |
| 666 |
\e\il\e\i\il\il\ir % B |
| 667 |
\end{Tree} |
| 668 |
\leavevmode |
| 669 |
B: \stack{-10pt}{\vd@st}{% |
| 670 |
10pt\\-10pt\\-10pt\\-10pt\\-10pt\\\ \\\var{loff}(\var{B})}% |
| 671 |
\hspace{1em}% |
| 672 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}% |
| 673 |
\hspace{1em}% |
| 674 |
\stack{-10pt}{\vd@st}{% |
| 675 |
10pt\\-10pt\\-10pt\\10pt\\-30pt\\\ \\\var{roff}(\var{B})}% |
| 676 |
\\[\figspace] |
| 677 |
\begin{Tree} |
| 678 |
\e\ir\ir\e |
| 679 |
\node{\type{dot}\rightonly\rght{\unskip\vrule height.8pt width5pt depth0pt}}% |
| 680 |
\i % A |
| 681 |
\e\il\e\i\il\il\ir % B |
| 682 |
\i % C |
| 683 |
\end{Tree} |
| 684 |
\leavevmode |
| 685 |
C: \stack{-10pt}{\vd@st}{% |
| 686 |
-20\\-10pt\\% |
| 687 |
\makebox[0pt][r]{\var{loff}(\var{A})$\smash{\left\{\vrule height\vd@st |
| 688 |
depth\vd@st width0pt\right.}$ }% |
| 689 |
10pt\\10pt\\% |
| 690 |
\makebox[0pt][r]{$\longrightarrow$ }% |
| 691 |
10pt\\% |
| 692 |
\makebox[0pt][r]{\raisebox{-.5\vd@st}{\var{loff}(\var{B})$\smash |
| 693 |
{\left\{\vrule height.5\vd@st |
| 694 |
depth.5\vd@st width0pt\right.}$ }}% |
| 695 |
\makebox[0pt][r]{-}10pt\\\ \\\var{loff}(\var{C})}% |
| 696 |
\hspace{1em}% |
| 697 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}% |
| 698 |
\hspace{1em}% |
| 699 |
\stack{-10pt}{\vd@st}{% |
| 700 |
20pt\\10pt\\-10pt\\-10pt% |
| 701 |
\makebox[0pt][l]{\raisebox{-.5\vd@st}{ |
| 702 |
$\smash{\left\}\vrule height2.5\vd@st |
| 703 |
depth2.5\vd@st width0pt\right.}$\var{roff}(\var{B})}}% |
| 704 |
\\10pt\\-30pt\\\ \\\var{roff}(\var{C})}% |
| 705 |
|
| 706 |
\vspace{\figspace} |
| 707 |
\centering |
| 708 |
\begin{tabular}{|l|r|r|r|} |
| 709 |
\hline |
| 710 |
&\multic{1}{c|}{\var{A}}&\multic{1}{c|}{\var{B}}&\multic{1}{c|}{\var{C}}\\ |
| 711 |
\hline |
| 712 |
height&\multic{1}{c|}{3}& \multic{1}{c|}{5}& \multic{1}{c|}{6}\\ |
| 713 |
type& \multic{1}{c|}{dot}&\multic{1}{c|}{dot}&\multic{1}{c|}{dot}\\ |
| 714 |
ltop& 2pt& 2pt& 2pt\\ |
| 715 |
rtop& 2pt& 2pt& 2pt\\ |
| 716 |
lmoff& -10pt& -30pt& -30pt\\ |
| 717 |
rmoff& 20pt& 10pt& 30pt\\ |
| 718 |
lboff& 10pt& -30pt& -10pt\\ |
| 719 |
rboff& 10pt& -30pt& -10pt\\ |
| 720 |
\hline |
| 721 |
\end{tabular}\qquad |
| 722 |
\begin{tabular}{|c|r|r|} |
| 723 |
\hline |
| 724 |
\multic{1}{|c|}{level}&\multic{1}{c|}{\var{totsep}}& |
| 725 |
\multic{1}{c|}{\var{currsep}}\\ |
| 726 |
\hline |
| 727 |
0&20pt&0/16pt\\ |
| 728 |
1&25pt&11/16\\ |
| 729 |
2&40pt&1/16pt\\ |
| 730 |
3&40pt&16pt\\ |
| 731 |
\hline |
| 732 |
\end{tabular} |
| 733 |
\caption{The \TeX{}trees \var{A} and~\var{B} are combined to form the |
| 734 |
larger \TeX{}\-tree~\var{C}. The small table gives the |
| 735 |
history of computation for \var{totsep} and \var{currsep}.} |
| 736 |
\label{AddInfo} |
| 737 |
\end{Figure} |
| 738 |
|
| 739 |
|
| 740 |
First we determine which tree is higher; this is |
| 741 |
\var{B} in the example. |
| 742 |
Then we have to compute the minimal distance |
| 743 |
between the roots of \var{A} and \var{B}, such that at all levels |
| 744 |
of the trees there is free space of at least \var{minsep} between |
| 745 |
the trees when they are drawn side by side. |
| 746 |
For this purpose we keep track of two values, \var{totsep} and |
| 747 |
\var{currsep}. The variables \var{totsep} and \var{currsep} |
| 748 |
hold the total distance between the roots and the distance |
| 749 |
between the rightmost node of \var{A} and the leftmost node |
| 750 |
of \var{B} at the current level. In order to calculate |
| 751 |
\var{totsep} and \var{currsep}, we start at level 0 and |
| 752 |
visit each level of the trees until we reach the bottom level |
| 753 |
of the smaller tree; this is \var{A} in our example. |
| 754 |
|
| 755 |
At level 0, the distance between the roots of \var{A} and \var{B} |
| 756 |
should be at least \var{minsep}. Therefore, we set |
| 757 |
$\var{totsep}:=\var{minsep} + \var{rtop}(\var{A}) |
| 758 |
+ \var{ltop}(\var{B})$ and $\var{currsep}:=\var{minsep}$. |
| 759 |
Using $\var{roff}(\var{A})$ and $\var{loff}(\var{B})$, we can |
| 760 |
proceed to calculate \var{currsep} for the next level. |
| 761 |
If $\var{currsep} < \var{minsep}$, we have to increase \var{totsep} by |
| 762 |
the difference and update \var{currsep}. This process is |
| 763 |
iterated until we reach the lowest level of \var{A}. |
| 764 |
Then \var{totsep} holds the final distance between the |
| 765 |
nodes of \var{A} and \var{B}, as calculated by the RT~algorithm. |
| 766 |
If the root of \var{C} is a significant node, then the additional space , |
| 767 |
which is 0pt by default, is added to \var{totsep}. |
| 768 |
However, the approach of synthesizing |
| 769 |
drawings from simple graphics characters allows only a finite |
| 770 |
number of orientations for the tree edges; therefore, \var{totsep} |
| 771 |
must be increased slightly to fit the next orientation |
| 772 |
available. |
| 773 |
|
| 774 |
Now we are ready to construct the box of \TeX{}tree~\var{C}. |
| 775 |
Simply put \var{A} and~\var{B} side by side, with the reference |
| 776 |
points \var{totsep}~units apart, insert a new node |
| 777 |
above them, and connect the parent and children by edges. |
| 778 |
|
| 779 |
Next, we update the additional information |
| 780 |
for \var{C}. This can be done by using the additional information |
| 781 |
for \var{A} and~\var{B}. |
| 782 |
Note that most components of $\var{roff}(\var{C})$ and |
| 783 |
$\var{lroff}(\var{C})$ are the same as in the higher tree, which |
| 784 |
is \var{B} in our case. |
| 785 |
So, if we can avoid moving this information around, we only have |
| 786 |
to access $\var{height}(\var{A}) + \var{const}$ many counters in |
| 787 |
order to update the additional information for \var{C}. |
| 788 |
This implies that we can apply the same argument as |
| 789 |
in~\cite{TidierTrees}, which gives |
| 790 |
us a running time of $\O(N)$ for drawing a tree with N nodes. |
| 791 |
|
| 792 |
Therefore, we must carefully design the storage allocation for |
| 793 |
the additional information of \TeX{}trees in order to fulfill the |
| 794 |
following requirements: |
| 795 |
If a new tree is built from |
| 796 |
two subtrees, the additional information of the new tree should |
| 797 |
share storage with its larger subtree. |
| 798 |
Organizational overhead, that is, |
| 799 |
pointers which keep track of the locations of different parts of additional |
| 800 |
information, must be avoided. |
| 801 |
This means that all the additional information |
| 802 |
for one \TeX{}tree should be stored in a row of consecutive dimension registers |
| 803 |
such that only one pointer granting access to the first element |
| 804 |
in this row is needed. |
| 805 |
On the other hand, each parent |
| 806 |
tree is higher and therefore needs more storage than its subtrees. |
| 807 |
So we must ensure that there is always enough space in the row |
| 808 |
for more information. |
| 809 |
|
| 810 |
The obvious way to fulfill these requirements is to use a stack and to |
| 811 |
allow only the topmost \TeX{}trees of this stack to be |
| 812 |
combined into a larger tree at any time. |
| 813 |
This leads to the following register allocation: A subsequent number of |
| 814 |
box registers contains the treeboxes of the subtrees in the stack. A |
| 815 |
subsequent number of token registers contains the type information for the |
| 816 |
nodes of the subtrees in the stack. For each subtree in the stack, |
| 817 |
a subsequent number of dimension registers contains the contour |
| 818 |
information of the subtree. The ordering of these groups of dimension |
| 819 |
registers reflects the ordering of the subtrees in the |
| 820 |
stack. Finally, a subsequent number of counter registers contains |
| 821 |
the height and the address of the first dimension register for |
| 822 |
each subtree in the stack. Four address counters store the addresses |
| 823 |
of the last treebox, type information, height, and address of contour |
| 824 |
information. A sketch of the register organization for a stack of \TeX{}trees |
| 825 |
is provided in \fig{Registers}. |
| 826 |
|
| 827 |
\begin{Figure} |
| 828 |
Dimension registers\\ |
| 829 |
\var{lmoff}(1) \var{rmoff}(1) \var{lboff}(1) \var{rboff}(1) \var{ltop}(1) |
| 830 |
\var{rtop}(1)\\ |
| 831 |
\var{loff}($h_1$) \var{roff}($h_1$) \dots\ \var{loff}(1) \var{roff}(1)\\ |
| 832 |
\dots\\ |
| 833 |
\var{lmoff}($n$) \var{rmoff}($n$) \var{lboff}($n$) \var{rboff}($n$) |
| 834 |
\var{ltop}($n$) \var{rtop}($n$)\\ |
| 835 |
\var{loff}($h_n$) \var{roff}($h_n$) \dots\ \var{loff}(1) \var{roff}(1)\\ |
| 836 |
\ \\ |
| 837 |
Counter registers\\ |
| 838 |
\var{lasttreebox} \var{lasttreeheight} \var{lasttreeinfo} \var{lasttreetype}\\ |
| 839 |
\var{treeheight}(1) \var{diminfo}(1) \dots\ \var{treeheight}($n$) |
| 840 |
\var{diminfo}($n$)\\ |
| 841 |
\ \\ |
| 842 |
Box registers\\ |
| 843 |
\var{treebox}(1) \dots\ \var{treebox}($n$)\\ |
| 844 |
\ \\ |
| 845 |
Token registers\\ |
| 846 |
\var{type}(1) \dots\ \var{type}($n$) |
| 847 |
|
| 848 |
\caption{\var{lasttreebox}, \var{lasttreeheight}, \var{lasttreeinfo}, |
| 849 |
\var{lasttreetype} contain pointers to \var{treebox}($n$) |
| 850 |
\var{treeheight}($n$), \var{lmoff}($n$), \var{type}($n$), |
| 851 |
\var{diminfo}($i$) contains a pointer to |
| 852 |
\var{lmoff}($i$). Unused dimension registers are |
| 853 |
allowed between the dimension registers of subsequent trees. The counter |
| 854 |
registers \var{lasttreebox},\ldots,\var{diminfo}($n$) serve as a directory |
| 855 |
mechanism to access the \TeX{}trees on the stack.} |
| 856 |
\label{Registers} |
| 857 |
\end{Figure} |
| 858 |
|
| 859 |
|
| 860 |
When a new node is pushed onto the stack, the treebox, type information, |
| 861 |
height, address of contour information, and contour information are |
| 862 |
stored in the next free registers of the appropriate type, and the |
| 863 |
four address counters are updated accordingly. |
| 864 |
|
| 865 |
When a new tree is formed from the topmost subtrees on the stack, |
| 866 |
the treebox, type information, height, and address of contour information |
| 867 |
of the new tree are sorted in the registers formerly used by the bottommost |
| 868 |
subtree that has occured in the construction step, and the four address registers are |
| 869 |
updated accordingly. This means that these informations for the subtrees |
| 870 |
are no longer accessible. The contour information of the new subtree |
| 871 |
is stored in the same registers as the contour information of the larger |
| 872 |
subtree used in the construction, apart from the left and right offset |
| 873 |
of the root to the left and right child, which are stored in the |
| 874 |
following dimension registers. That means that gaps can occur |
| 875 |
between the contour information of subsequent subtrees in the |
| 876 |
stack, namely when the right subtree, which is on a higher position on the |
| 877 |
stack, is higher than the left one. In order to avoid these |
| 878 |
gaps, the user can specify an option \verb.\lefttop. when entering a |
| 879 |
binary node, which makes the topmost tree in the stack the |
| 880 |
left subtree of the node. |
| 881 |
|
| 882 |
This stack concept also has consequences for the design of the user interface |
| 883 |
that is discussed in Section~\ref{Interface}. |
| 884 |
|
| 885 |
\section{Space cost analysis} |
| 886 |
|
| 887 |
Suppose we want to draw a unary-binary tree $T$ of height $h$ having |
| 888 |
$N$ nodes\footnote{The height $h$ and the number of nodes $N$ refer to the |
| 889 |
drawing of the tree. $N$ is the number of circles, squares etc.~actually |
| 890 |
drawn, and $h$ is the number of levels in the drawing minus 1.}. |
| 891 |
According to our internal representation, |
| 892 |
for each subtree in the stack we need |
| 893 |
|
| 894 |
\begin{enumerate} |
| 895 |
\item one box register to store the box of the \TeX{}tree. |
| 896 |
\item one token register to store the type of the root of the subtree. |
| 897 |
\item $2h^\prime+6$ dimension registers to store the additional |
| 898 |
information, where $h^\prime$ is the height of the |
| 899 |
subtree. |
| 900 |
\item three counter registers to store the register numbers of the |
| 901 |
box register, the token register, and the first dimension register above. |
| 902 |
\end{enumerate} |
| 903 |
|
| 904 |
The following lemma relates to $h$ and $N$ the number |
| 905 |
of subtrees of $T$ which are on the |
| 906 |
stack simultaneously and their heights. |
| 907 |
|
| 908 |
\begin{lemma} |
| 909 |
\begin{enumerate} |
| 910 |
\item At any time, there are at most $h+1$ subtrees of $T$ on the |
| 911 |
stack. |
| 912 |
\item For each set $\T$ of subtrees of $T$ which are on the stack |
| 913 |
simultaneously we have |
| 914 |
$$\sum_{T^\prime\in \T}({\rm ht}(T^\prime)+1) |
| 915 |
\le\min(N,{(h+1)(h+2)\over2}).$$ |
| 916 |
\end{enumerate} |
| 917 |
\end{lemma} |
| 918 |
|
| 919 |
\begin{proof} |
| 920 |
\begin{enumerate} |
| 921 |
\item By induction on $h$.\label{stackdepth} |
| 922 |
\item The trees in $\T$ are pairwise disjoint, and each tree of |
| 923 |
height $h^\prime$ has at least $h^\prime+1$ nodes. This implies |
| 924 |
$$\sum_{T^\prime\in \T}({\rm ht}(T^\prime)+1) |
| 925 |
\le N.$$ |
| 926 |
The second part is shown by induction on $h$. |
| 927 |
The basis $h=0$ is clear. |
| 928 |
Assume the assumption holds for all trees of height less than |
| 929 |
$h$. If $\T$ |
| 930 |
contains only subtrees of either the left or the right subtree |
| 931 |
of $T$, we have |
| 932 |
$$\sum_{T^\prime\in \T}({\rm ht}(T^\prime)+1)\le |
| 933 |
{h(h+1)\over2}\le{(h+1)(h+2)\over2}.$$ |
| 934 |
Otherwise, $\T$ contains the left or the right subtree $T_s$ of |
| 935 |
$T$. Then all elements of $\T-\{T_s\}$ belong to the other |
| 936 |
subtree. This implies |
| 937 |
\begin{eqnarray*} |
| 938 |
\sum_{T^\prime\in \T}({\rm ht}(T^\prime)+1)&\le& |
| 939 |
{\rm ht}(T_s)+1 |
| 940 |
+\sum_{T^\prime\in \T-\{T_s\}}({\rm ht}(T^\prime)+1)\\ |
| 941 |
&\le& h+{h(h+1)\over2}\le{(h+1)(h+2)\over2}.\proofend |
| 942 |
\end{eqnarray*} |
| 943 |
\end{enumerate} |
| 944 |
\end{proof} |
| 945 |
|
| 946 |
Therefore, our implementation uses at most $9h+2\min(N,(h+1)(h+2)/2)$ |
| 947 |
registers. In order to compare this with the |
| 948 |
$10N$ registers used in the straightforward implementation, |
| 949 |
an estimation of the average height of a tree with $N$ nodes is |
| 950 |
needed. Several results, depending on the type of trees and of the |
| 951 |
randomization model, are cited in \fig{Stat}, which |
| 952 |
compares the number of registers used in a straightforward |
| 953 |
implementation with the average number of registers used in our |
| 954 |
implementation. This table shows clearly the advantage of our |
| 955 |
implementation. |
| 956 |
|
| 957 |
\begin{Figure} |
| 958 |
\centering |
| 959 |
\begin{tabular}{|c|c|c|c|c|} |
| 960 |
\hline |
| 961 |
®isters&\multicolumn{3}{c|}{average registers}\\ |
| 962 |
\cline{3-5} |
| 963 |
nodes&(straight-&extended&unary-binary&binary\\ |
| 964 |
&forward)&binary trees&trees& |
| 965 |
search trees\\ |
| 966 |
&&($\sqrt{\pi n}$) \cite{AverageHeight}& |
| 967 |
($\sqrt{3\pi n}$) ~\cite{BinaryTrees}& |
| 968 |
($4.311\log n$) \cite{BinarySearchTrees}\\ |
| 969 |
\hline |
| 970 |
\ds8& \ds80& \ds61.12& \ds94.15& \ds51.04\\ |
| 971 |
\ds9& \ds90& \ds65.86& 100.89& \ds55.02\\ |
| 972 |
10& 100& \ds70.44& 107.37& \ds58.80\\ |
| 973 |
11& 110& \ds74.91& 113.64& \ds62.41\\ |
| 974 |
12& 120& \ds79.26& 119.71& \ds65.87\\ |
| 975 |
20& 200& 111.34& 163.56& \ds90.48\\ |
| 976 |
30& 300& 147.37& 211.33& 117.31\\ |
| 977 |
40& 400& 180.89& 254.75& 132.58\\ |
| 978 |
50& 500& 212.80& 295.37& 143.54\\ |
| 979 |
\hline |
| 980 |
\end{tabular} |
| 981 |
|
| 982 |
\caption{The numbers of registers used by a straightforward implementation |
| 983 |
(second column) and by our modified implementation (third to fifth column) |
| 984 |
of the RT~algorithm are |
| 985 |
given for different types of trees and randomization models. |
| 986 |
The formula in parentheses indicates the average height of the respective class |
| 987 |
of trees, as depending on the number of nodes.} |
| 988 |
\label{Stat} |
| 989 |
\end{Figure} |
| 990 |
|
| 991 |
|
| 992 |
\section{The user interface}\label{Interface} |
| 993 |
|
| 994 |
\subsection{General design considerations} |
| 995 |
|
| 996 |
The user interface of \TreeTeX{} has been designed in the spirit of |
| 997 |
the thorough separation of the logical description of document components |
| 998 |
and their layout; see~\cite{DocumentFormatting,GML}. This concept |
| 999 |
ensures both uniformity and flexibility of document layout and frees |
| 1000 |
authors from layout problems which have nothing to do with the |
| 1001 |
substance of their work. For some powerful implementations and projects |
| 1002 |
see \cite{Tables,Karlsruhe,LaTeX,Grif,Scribe}. |
| 1003 |
|
| 1004 |
In this context, the description of a tree is given in a purely |
| 1005 |
logical form, and layout variations are defined by a separate style |
| 1006 |
command which is valid for all trees of a document. |
| 1007 |
|
| 1008 |
A second design principle is to provide defaults for all specifications, |
| 1009 |
thereby allowing the user to omit many definitions |
| 1010 |
if the defaults match what he or she wants. |
| 1011 |
|
| 1012 |
The node descriptions of a tree must be entered in postorder. |
| 1013 |
This fits the internal representation |
| 1014 |
of \TeX{}trees best. Although this is a natural method of describing a |
| 1015 |
tree, a user might prefer more flexible description methods. |
| 1016 |
However, note that instances of well defined tree classes can be described |
| 1017 |
easily by \TeX{} macros. In section~\ref{ExampleClasses}. we give examples of macros |
| 1018 |
for complete binary trees and Fibonacci trees. |
| 1019 |
|
| 1020 |
\TreeTeX{} uses the picture making macros of \LaTeX. If \TreeTeX{} is used with |
| 1021 |
any other macro package or format, the picture macros of |
| 1022 |
\LaTeX{} are included automatically. |
| 1023 |
|
| 1024 |
\subsection{The description of a tree} |
| 1025 |
|
| 1026 |
The description of a tree is started by the command \verb.\beginTree. |
| 1027 |
and closed by \verb.\endTree. (or \verb.\begin{Tree}. and |
| 1028 |
\verb.\end{Tree}. in \LaTeX). The description can be |
| 1029 |
started in any mode; it defines a box and two dimensions. The |
| 1030 |
box is stored in the box register \verb.\TeXTree. and contains the |
| 1031 |
drawing of the tree. The box has zero height and width, and its depth |
| 1032 |
is the height of the drawing. The reference point is in the |
| 1033 |
center of the node of the tree. The dimensions are stored in the |
| 1034 |
registers \verb.\leftdist. and \verb.\rightdist. and describe |
| 1035 |
the distance between the reference point and the left and |
| 1036 |
right margin of the drawing. These data can be used to position the |
| 1037 |
drawing of the tree. |
| 1038 |
|
| 1039 |
Note that the \TreeTeX{} macros don't contribute anything to the current |
| 1040 |
page but only store their results in the registers |
| 1041 |
\verb.\TeXTree., \verb.\leftdist., and \verb.\rightdist.. It is the |
| 1042 |
user's job to put the drawing onto the page, using the |
| 1043 |
commands \verb.\copy. or \verb.\box. (or \verb.\usebox. in \LaTeX). |
| 1044 |
|
| 1045 |
Each matching pair of \verb.\beginTree. and \verb.\endTree. must |
| 1046 |
contain the description for only \emph{one} tree. |
| 1047 |
Descriptions of trees cannot be nested and |
| 1048 |
new registers cannot be allocated inside |
| 1049 |
a matching pair of \verb.\beginTree. and \verb.\endTree.. |
| 1050 |
|
| 1051 |
As already stated, each tree description defines the nodes of the tree in |
| 1052 |
postorder, that is, a tree description is a particular sequence of node |
| 1053 |
descriptions. |
| 1054 |
|
| 1055 |
A node description, in turn, consists of the macro \verb.\node., |
| 1056 |
followed by a list of node options, included in braces. The list |
| 1057 |
of node options may be empty. The node options describe the labels, |
| 1058 |
the geometric shape (type), and the outdegree of the node. Default values are |
| 1059 |
provided for all options which are not explicitly specified. |
| 1060 |
The following node options are available: |
| 1061 |
|
| 1062 |
\begin{enumerate} |
| 1063 |
\item[1.] \verb.\lft{<label>}., \verb.\rght{<label>}., |
| 1064 |
\verb.\cntr{<label>}.,\\\verb.\bnth{<label>}.:\\ |
| 1065 |
These options describe the labels which are put to the left of, to the |
| 1066 |
right of, in the |
| 1067 |
center of, or beneath the node (the latter only makes sense for |
| 1068 |
external nodes). The arguments of these macros are processed in |
| 1069 |
internal horizontal mode (LR-mode in \LaTeX), but can consist of |
| 1070 |
arbitrary nested boxes for more sophisticated labels. For each of |
| 1071 |
these options, the default is an empty label. |
| 1072 |
|
| 1073 |
\item[2.] \verb.\external., \verb.\unary., |
| 1074 |
\verb.\leftonly., \verb.\rightonly.:\\ |
| 1075 |
These options describe the outdegree |
| 1076 |
of the node. |
| 1077 |
The default is binary (no outdegree option is specified). |
| 1078 |
|
| 1079 |
\item[3.] \verb.\type{<type>}.:\\ |
| 1080 |
This option describes the type or geometric shape of the node. |
| 1081 |
\verb.<type>. can have the values \verb.square., |
| 1082 |
\verb.dot., \verb.text., or \verb.frame.. |
| 1083 |
The default value is \verb.circle. (no type is specified). A node of type |
| 1084 |
\verb.square. has a fixed width, while a node of type \verb.frame. has its |
| 1085 |
width determined by the center label. A node of type \verb.text. has no frame |
| 1086 |
around its center label. The center label can have arbitrary width. |
| 1087 |
|
| 1088 |
\item[3.] \verb.\leftthick., \verb.\rightthick.: |
| 1089 |
These options change the thickness of the left or right outgoing edge of |
| 1090 |
a binary node. Defaults are thin edges (neither option is specified). |
| 1091 |
|
| 1092 |
\item[4.] \verb.\lefttop.:\\ |
| 1093 |
The node option \verb.\lefttop. in a binary node makes the |
| 1094 |
last entered subtree the left child of the node (the right child is the |
| 1095 |
default). This option helps to cut down on the number of dimension registers |
| 1096 |
used during the construction of a tree. As a rule of thumb, |
| 1097 |
this option is recommended when the left subtree has a smaller |
| 1098 |
height than the right subtree, that is, |
| 1099 |
in this case the right subtree should |
| 1100 |
be entered before the left one and their parent should be assigned the option |
| 1101 |
\verb.\lefttop.. |
| 1102 |
\end{enumerate} |
| 1103 |
|
| 1104 |
\subsection{Macros for classes of trees} |
| 1105 |
\label{ExampleClasses} |
| 1106 |
|
| 1107 |
Tree descriptions can be produced by macros. This is especially useful |
| 1108 |
for trees which belong to a larger class of trees and which can be specified |
| 1109 |
by some simple parameters. A small library of such |
| 1110 |
macros is provided in the file \verb!TreeClasses.tex!. |
| 1111 |
|
| 1112 |
\begin{enumerate} |
| 1113 |
\item[1.] \verb.\treesymbol{<node options>}.:\\ |
| 1114 |
This macro produces a triangular tree symbol which can be included in |
| 1115 |
a tree description instead of an external node. Labels for these |
| 1116 |
tree symbols are described as for ordinary nodes. In addition, the |
| 1117 |
options \verb.\lvls{<number>}. and \verb.\slnt{<number>}. |
| 1118 |
are provided. \verb.\lvls. defines the number of levels in the |
| 1119 |
tree over which the triangle extends, and \verb.\slnt. gives |
| 1120 |
the slant of the sides of the triangle, ranging from 1~(minimal) |
| 1121 |
to 24~(maximal). On the other hand, |
| 1122 |
\verb.\treesymbol. does not expand to a tree description, because |
| 1123 |
a tree symbol cannot be built from subtrees, and, on the other hand, |
| 1124 |
it is not a node, because it is allowed to extend over several tree |
| 1125 |
levels and therefore has a longer contour than an ordinary node. |
| 1126 |
|
| 1127 |
\item[2.] \verb.\binary{<bin specification>}.:\\ |
| 1128 |
This macro truly expands to a tree description. It produces |
| 1129 |
a complete binary tree, that is, an extended binary tree, |
| 1130 |
where, for a given $h$, all external nodes appear at level $h$ |
| 1131 |
or $h-1$, and all external nodes at level $h$ lie left of those at |
| 1132 |
level $h-1$. \verb.<bin specification>. consists of the |
| 1133 |
following options: |
| 1134 |
\verb.\no{<number>}. defines the number of internal nodes, |
| 1135 |
with \verb.<number>. greater than 0, and |
| 1136 |
\verb.\squareleaves. produces leaves of type |
| 1137 |
\verb.square.. Defaults are \verb.\no{1}. and |
| 1138 |
leaves of type \verb.circle.. |
| 1139 |
|
| 1140 |
\item[3.] \verb.fibonacci{<fib specification>}.:\\ |
| 1141 |
This macro produces a Fibonacci tree. |
| 1142 |
\verb.<fib specification>. allows for the three options |
| 1143 |
\verb.\hght{<number>}., \verb.\unarynodes., |
| 1144 |
and \verb.\squareleaves.. |
| 1145 |
Normally, a Fibonacci tree of height $h+2$ is a binary tree |
| 1146 |
with Fibonacci trees of height $h$ and $h+1$ as left and |
| 1147 |
right subtrees. The option \verb.\unarynodes. means that the |
| 1148 |
Fibonacci tree is augmented by unary nodes such that each |
| 1149 |
two subtree siblings have the same height. These are examples |
| 1150 |
of what has been called brother-trees in the literature; |
| 1151 |
see~\cite{Brother}. Defaults are |
| 1152 |
\verb.\hght{0}., the unaugmented version of a Fibonacci tree, |
| 1153 |
and external nodes of type \verb.circle.. |
| 1154 |
\end{enumerate} |
| 1155 |
|
| 1156 |
\subsection{Style options for trees} |
| 1157 |
\sloppy |
| 1158 |
The \TreeTeX{} package includes a style command |
| 1159 |
\verb.\Treestyle{<style option>}., where \verb.<style option>. |
| 1160 |
contains all the parameter settings the user might want |
| 1161 |
to change. |
| 1162 |
Normally, the command \verb.\Treestyle. appears only once at the beginning |
| 1163 |
of the document and the style options are valid for all trees of the |
| 1164 |
document. |
| 1165 |
|
| 1166 |
\fussy |
| 1167 |
The changes in the style options are global. A \verb.\Treestyle. command |
| 1168 |
changes only the specified style options; non-specified options retain |
| 1169 |
the last specified value or the default value, respectively. The following |
| 1170 |
style options are available: |
| 1171 |
|
| 1172 |
\begin{enumerate} |
| 1173 |
\item[1.] \verb.\treefonts{<font options>}.:\\ |
| 1174 |
\sloppy |
| 1175 |
\verb.\treefonts. is invoked by \verb.\beginTree., and it simply executes |
| 1176 |
whatever is specified in \verb.<font options>.. Defaults are |
| 1177 |
\verb.\treefonts{\tenrm}. (or \verb.\treefonts{\normalsize\rm}. in |
| 1178 |
\LaTeX). |
| 1179 |
|
| 1180 |
\fussy |
| 1181 |
\item[2.] \verb.\nodesize{<size>}.:\\ |
| 1182 |
\verb.\nodesize. defines the size of the nodes. \verb.<size>. is a |
| 1183 |
dimension and specifies the diameter of circle nodes. The |
| 1184 |
width of square nodes is adjusted accordingly to be slightly |
| 1185 |
smaller than the diameter of circle nodes in order to |
| 1186 |
balance their appearance. Furthermore, |
| 1187 |
\verb.\nodesize. adjusts the amount of space by which the |
| 1188 |
baseline of the labels is placed beneath the center of the node. |
| 1189 |
The default value of \verb.\nodesize. suits the default of |
| 1190 |
\verb.\treefonts. (taking into account the size option |
| 1191 |
of \LaTeX's document style). |
| 1192 |
|
| 1193 |
\item[3.] \verb.\vdist{<dimen>}., \verb.\minsep{<dimen>}., |
| 1194 |
\verb.\addsep{<dimen>}.:\\ |
| 1195 |
\sloppy |
| 1196 |
\verb.vdist. specifies the vertical distance between two |
| 1197 |
subsequent levels of the tree. Default is \verb.\vdist{60pt}.. |
| 1198 |
\verb.\minsep. specifies the minimal horizontal distance between two |
| 1199 |
adjacent nodes. Default is \verb.\minsep{20pt}.. |
| 1200 |
\verb.\addsep. specifies the additional amount of horizontal space |
| 1201 |
by which two subtree siblings are pushed apart farther than |
| 1202 |
calculated by the RT~algorithm, |
| 1203 |
if the level at which they are closest is beneath |
| 1204 |
their root level. Default is \verb.\addsep{0pt}. |
| 1205 |
|
| 1206 |
\fussy |
| 1207 |
\item[4.] \verb.\extended., \verb.\nonextended.:\\ |
| 1208 |
With the option \verb.\extended. in effect, the nodes of a binary |
| 1209 |
tree are placed in exactly the same way as they would be in the |
| 1210 |
associated extended version of the tree (the missing nodes are |
| 1211 |
assumed to have no labels). The default is \verb.\nonextended., |
| 1212 |
that is the usual layout. |
| 1213 |
\end{enumerate} |
| 1214 |
|
| 1215 |
Some examples of tree descriptions |
| 1216 |
are given in the next figures. |
| 1217 |
A detailed description of the |
| 1218 |
\TreeTeX{} macros is given in~\cite{TreeTeX}. |
| 1219 |
|
| 1220 |
\Treestyle{\vdist{60pt}} |
| 1221 |
\dummyhalfcenterdim@n=10pt |
| 1222 |
|
| 1223 |
\begin{Figure} |
| 1224 |
\centering |
| 1225 |
\begin{Tree} |
| 1226 |
\node{\external\bnth{first}\cntr{1}\lft{Beeton}} |
| 1227 |
\node{\external\cntr{3}\rght{Kellermann}} |
| 1228 |
\node{\cntr{2}\lft{Carnes}} |
| 1229 |
\node{\external\cntr{6}\lft{Plass}} |
| 1230 |
\node{\external\bnth{last}\cntr{8}\rght{Tobin}} |
| 1231 |
\node{\cntr{7}\rght{Spivak}} |
| 1232 |
\node{\leftonly\cntr{5}\rght{Lamport}} |
| 1233 |
\node{\cntr{4}\rght{Knuth}} |
| 1234 |
\end{Tree} |
| 1235 |
|
| 1236 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}\ |
| 1237 |
|
| 1238 |
\begin{verbatim} |
| 1239 |
\begin{Tree} |
| 1240 |
\node{\external\bnth{first}\cntr{1}\lft{Beeton}} |
| 1241 |
\node{\external\cntr{3}\rght{Kellermann}} |
| 1242 |
\node{\cntr{2}\lft{Carnes}} |
| 1243 |
\node{\external\cntr{6}\lft{Plass}} |
| 1244 |
\node{\external\bnth{last}\cntr{8}\rght{Tobin}} |
| 1245 |
\node{\cntr{7}\rght{Spivak}} |
| 1246 |
\node{\leftonly\cntr{5}\rght{Lamport}} |
| 1247 |
\node{\cntr{4}\rght{Knuth}} |
| 1248 |
\end{Tree} |
| 1249 |
|
| 1250 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist} |
| 1251 |
\end{verbatim} |
| 1252 |
|
| 1253 |
\caption{This is an example of a tree that includes labels.} |
| 1254 |
\end{Figure} |
| 1255 |
|
| 1256 |
\begin{Figure} |
| 1257 |
\centering |
| 1258 |
\begin{Tree} |
| 1259 |
\node{\external\type{frame}\bnth{first}\cntr{Beeton}} |
| 1260 |
\node{\external\type{frame}\cntr{Kellermann}} |
| 1261 |
\node{\type{frame}\cntr{Carnes}} |
| 1262 |
\node{\external\type{frame}\cntr{Plass}} |
| 1263 |
\node{\external\type{frame}\bnth{last}\cntr{Tobin}} |
| 1264 |
\node{\type{frame}\cntr{Spivak}} |
| 1265 |
\node{\leftonly\type{frame}\cntr{Lamport}} |
| 1266 |
\node{\type{frame}\cntr{Knuth}} |
| 1267 |
\end{Tree} |
| 1268 |
|
| 1269 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}\ |
| 1270 |
|
| 1271 |
\begin{verbatim} |
| 1272 |
\begin{Tree} |
| 1273 |
\node{\external\type{frame}\bnth{first}\cntr{Beeton}} |
| 1274 |
\node{\external\type{frame}\cntr{Kellermann}} |
| 1275 |
\node{\type{frame}\cntr{Carnes}} |
| 1276 |
\node{\external\type{frame}\cntr{Plass}} |
| 1277 |
\node{\external\type{frame}\bnth{last}\cntr{Tobin}} |
| 1278 |
\node{\type{frame}\cntr{Spivak}} |
| 1279 |
\node{\leftonly\type{frame}\cntr{Lamport}} |
| 1280 |
\node{\type{frame}\cntr{Knuth}} |
| 1281 |
\end{Tree} |
| 1282 |
|
| 1283 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist} |
| 1284 |
\end{verbatim} |
| 1285 |
\caption{This is an example of a tree with framed center labels.} |
| 1286 |
\end{Figure} |
| 1287 |
|
| 1288 |
\begin{Figure} |
| 1289 |
\centering |
| 1290 |
\begin{Tree} |
| 1291 |
\binary{\no{6}\squareleaves} |
| 1292 |
\end{Tree} |
| 1293 |
|
| 1294 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}\ |
| 1295 |
|
| 1296 |
\begin{verbatim} |
| 1297 |
\begin{Tree} |
| 1298 |
\binary{\no{6}\squareleaves} |
| 1299 |
\end{Tree} |
| 1300 |
|
| 1301 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist} |
| 1302 |
\end{verbatim} |
| 1303 |
\caption{This is an example of a complete binary tree.} |
| 1304 |
\end{Figure} |
| 1305 |
|
| 1306 |
|
| 1307 |
\begin{Figure} |
| 1308 |
\centering |
| 1309 |
\begin{Tree} |
| 1310 |
\fibonacci{\hght{4}\unarynodes\squareleaves} |
| 1311 |
\end{Tree} |
| 1312 |
|
| 1313 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist}\ |
| 1314 |
|
| 1315 |
\begin{verbatim} |
| 1316 |
\begin{Tree} |
| 1317 |
\fibonacci{\hght{4}\unarynodes\squareleaves} |
| 1318 |
\end{Tree} |
| 1319 |
\hspace{\leftdist}\usebox{\TeXTree}\hspace{\rightdist} |
| 1320 |
\end{verbatim} |
| 1321 |
|
| 1322 |
\caption{This is an example of a Fibonacci tree.} |
| 1323 |
\end{Figure} |
| 1324 |
|
| 1325 |
|
| 1326 |
\clearpage |
| 1327 |
\bibliography{trees} |
| 1328 |
\end{document} |
| 1329 |
|
| 1330 |
|
| 1331 |
|