Binary Trees in Bridges
BinTreeElement<E> implements a binary tree element in BRIDGES and is inherited from Element<E>How does the BinTreeElement<E> work?
BinTreeElement<E> is another type of container that has two links
pointing to its two children, also binary tree elements. By convention,
these two links are called "left" and "right and the top of the tree is
referred to as the "root".
In the example above, Root has two links, so calling Root.getLeft() will
return the TreeElement T1 and calling Root.getRight() will return the
TreeElement T2.
Note that there is no pointer from T1 or any other element back to its root.
How does a BinTreeElement<E> differ from a DLelement<E>?
Structurally, DLelement<E> and TreeElement<E> are similar with 2 emanating links, but they are used in very different data structures. In a doubly linked list, the links point to the immediately following and previous element, while in the binary tree they point to its two children(recursively, as can be seen in the above example).
See also
This tutorial gives an introduction to the usage of binary trees. You can find the complete documentation of the features in the Doxygen documentation of the following classes and functions:
- BinTreeElement [Java] [C++] [Python]
- Tree [Java] [C++] [Python]
- Element [Java] [C++] [Python]
- ElementVisualizer [Java] [C++] [Python]
- LinkVisualizer [Java] [C++] [Python]
- Color [Java] [C++] [Python]
BinTreeElement - BRIDGES Example: A Huffman Coding Tree
- This example illustrates construction of a Huffman coding tree, an application of a binary tree. The tree is manually created for a small alphabet.
- Hit the `l' key to turn on the labels to see the Huffman tree labels/values. from left to right and accessed by an integer index (begining at 0).
- In the example, the Huffman tree is built, visual attributes assigned and visualized.
Bridges Visualization
- Once all your code is in order, run your program.
- Assuming all your code is correct and it compiles correctly, a link to the Bridges website will be generated.
- Copy/paste this link into your favorite browser to view a visualization of the data structure you’ve just created.
- It should look something like this:
Well done! You’ve just created your Bridges Binary Tree project!