K-ary tree

In graph theory, a k-ary tree is a rooted tree in which each node has no more than k children. It is also sometimes known as a k-way tree, an N-ary tree, or an M-ary tree. A binary tree is the special case where k=2.

Types of k-ary trees

Properties of k-ary trees

\left\lceil\log_k (k - 1) + \log_k (\text{number of nodes}) - 1\right\rceil.

Note: A tree containing only one node is taken to be of height 0 for this formula to be applicable.

Note: The formula is not applicable for a 2-ary tree with height 0, as the ceiling operator approximates and simplifies the true formula, which can be described as

\log_k [(k - 1) \cdot (\text{number of nodes}) + 1] - 1,\; k \ge 2.

Methods for storing k-ary trees

Arrays

k-ary trees can also be stored in breadth-first order as an implicit data structure in arrays, and if the tree is a complete k-ary tree, this method wastes no space. In this compact arrangement, if a node has an index i, its c-th child is found at index k\cdot i+1+c, while its parent (if any) is found at index \left \lfloor \frac{i-1}{k} \right \rfloor (assuming the root has index zero, meaning a 0-based array). This method benefits from more compact storage and better locality of reference, particularly during a preorder traversal.

See also

References

  1. 1 2 "Ordered Trees". Retrieved 19 November 2012.
  2. Black, Paul E. (20 April 2011). "perfect k-ary tree". U.S. National Institute of Standards and Technology. Retrieved 10 October 2011.

External links


This article is issued from Wikipedia - version of the Tuesday, April 19, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.