![[ubiqx]](images/ubiqx.logo.gif)
This is really where the ubiqx library started. I was taking a graduate class in Compiler Design (a long time ago). The text stated that binary trees would be a poor choice for maintaining a symbol table so, of course, that's what I decided to use. Simple binary trees were fairly easy to do, so I went for AVL height-balaced trees instead. Needless to say, the compiler I wrote worked just fine. I refined the code over the years and then added the Splay trees (which are niftier than the AVL trees, IMHO).The ubi_BinTree and ubi_AVLtree modules were originally written for the Amiga. I wanted to be very careful with stack space under AmigaOS, which is why the implementation is non-recursive. Also, AmigaOS was written in plain-old C using object-oriented concepts--a style I tried to emulate.
Binary trees are typically defined as a collection of linked
nodes such that each node has zero, one, or two child nodes.
Most implementations manage the tree using recursive function calls, but
the ubiqx implementation of binary trees is non-recursive.
Depending upon your experience with recursion, this may make the code
easier or harder to figure out.
There really are a lot of interesting ways to write binary trees. I know of some folks who use empty child pointers to point to the sequentially previous or next node in the tree (a flag is used to indicate how the pointer is being used). This is known as a Threaded Tree.
The remainder of this section attempts to describe how to use the
ubiqx tree modules. If you want to know more about binary trees in
general, see the reference section below.
(1)
\
(2)
\
(4)
/ \
(3) (6)
/ \
(5) (7)
If the data entered into a simple binary tree is pre-sorted, the resultant tree will look, and work, like an ordered linked list. If the data is random, the tree will be "bushier", but it is not likely to be perfectly balanced. Balancing the tree provides the best performance for the search operation, at the cost of some overhead. That being the case, the ubi_BinTree module is suited for:
| Copyright © 1998-2002 by Christopher R. Hertel | ubiqx development uninq. |