Now for a forest of trees.
Trees are likely the most varied of all data structures. There are specialized trees for applications in computer graphics, astrophysics, engineering, text processing, databases, and compression (just to name a few). Trying to categorize trees into a small number of bins is somewhat pointless but I'll describe some of the broader types.
First some terminology.
The top of the tree is the root. This is the only node in the tree which has no parents.
The parent of a node is the node which is higher in the tree. A node will only ever have one parent.
The children of a node are all the nodes which are connected and one step lower in the tree.
An interior node is one which has both a parent and at least one child.
A leaf node is one which has no children.
The height of a tree is the distance from the root to the lowest child.
The depth of a node is the distance from the root to that node.
Now for some distinguishing characteristics of trees.
What is the maximum number of children which a node can have?
Some common numbers of children are
2 - binary tree
4 - quadtree
8 - octree
N - kd-tree, n-ary tree, radix tree, etc...
Do interior nodes hold elements?
A standard binary search tree stores its elements at every node whereas a red-black tree stores elements only as children.
How do we access/insert nodes?
There are many binary trees which differ only in the manner in which nodes are inserted.
Balanced trees rotate their nodes to keep the tree balanced.
Splay trees optimize themselves based on the access pattern.
Heaps reorganize themselves to keep the largest/smallest node at the root.
Some of the specialized trees are,
Barnes-Hut quad-trees which are used for astrophysics simulation.
Huffman coding trees which are used in compression.
BSP trees for computer graphics.
B* trees which are used in databases.
You could easily spend years studying nothing but trees.
Comments
Post a Comment