## M-array Tree in Discrete MathematicsAn m-array tree can be described as a generalization of a binary tree in which each and every node has M or less children. In other words, a tree will be known as the m array tree if each node of the tree does not contain more than m children. A binary tree will be known as the M-ary tree if it contains M = 2. With the help of following image, we can see an example of M-ary tree where M = 3. ## Types of M-ary tree- The given tree will be known as the full M-ary tree if every node of the M-ary tree must contain either 0 or M children.
- The tree will be known as the
**perfect tree**if every leaf node of this tree is at the same depth. - The tree will be known as the
**complete tree**if all levels of the m-ary tree except the last one are**full**. In the complete tree, every non-leaf node will have M children. However, if the last level of the tree is**incomplete**, then all the nodes of the given tree will be**as far left as possible**.
## Properties of M-ary treeThere are various properties in m ary tree, and some of them are described as follows: If there is a full m ary tree, which has i internal vertices, then we can calculate the vertices and leaves of that tree with the help of following formula:
Among 13 vertices, there is a root vertice, and the remaining 12 vertices are children of those 4 internal vertices. Now we will calculate the leaves of the tree with the help of following formula: Hence there will be 13 vertices and 9 numbers of leaves. ## TraversalThe binary trees and the M ary tree both have the same properties, which are described as follows:
In the process of pre-order traversal, we will first visit a root node, and then we will traverse to its subtree, which contains the left subtree and the right subtree. So after visiting the root node, we will first traverse the left subtree, and then we will traverse the right subtree. We can only visit one node at a time. The name "preorder traverse" also refers to the root node coming before the left and right subtree. In the preorder traverse, the time complexity is O(n). In the following form, we can represent the process of preorder traversal like this:
In the process of post-order traversal, we will follow the
In the process of in-order traversal, we will follow the There is one more way in which we can explain the traversal of m ary tree. The traversal of binary tree and the m ary tree are both similar. But there can be a case where m>2, which contains more than two children per node, so we have to define the notation of left and right subtrees. We can get the left and right subtree with the help of dividing the list of children nodes of the tree into two groups. With the help of defining the order on the m children of a node, we will constitute some part of the node on the left subtree, i.e., {0, 1,... m/2}, and we will constitute the other part of the node on the right subtree, i.e., {m/2, ...., m}. ## Method of storing m-ary treesWe can store the m ary tree with the help of two ways: we can use an array, or we can use a pointer-based. Now we will explain them one by one like this:
## Converting m-ary tree into binary treeSuppose we try to convert an arbitrary m ary tree into a binary tree. In this case, we have to use a constant factor, which is used to only increase the height of a tree, and it will not be useful to affect the overall worst-case time complexity. First, we will form a link list with the help of linking all the intermediate children nodes of the given parent node. After that, we will keep the link from parent to the first child, i.e., the leftmost child, and in this process, we will remove all the other links to the rest children. ↓ ↓ ↓ ## Applications of M-ary treesThere are a lot of applications in the M-ary tree, and some of them are described as follows: - The M-ary tree is useful in color quantization.
- We can use it in mesh generation and image processing.
- In case of natural language processing applications, we will use the parse and grammar trees.
- In case of rendering and collision detection, we can use game engines.
- We can represent the structure of program code with the help of abstract syntax trees.
- We can show a file system data structure. Here node is used to represent the files and folders and many more places.
In the following image, we will indicate an example of a grammar tree like this: Next TopicMatrix in Discrete mathematics |