Marray Tree in Discrete MathematicsAn marray 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 Mary tree if it contains M = 2. With the help of following image, we can see an example of Mary tree where M = 3. Types of Mary tree
Properties of Mary 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: For example: Suppose there are 4 internal vertices and m = 3 in a tree. Now we have to calculate the number of vertices and number of leaves in that tree. Solution: From the question, we have m = 3, and i = 4 and we know that 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: Preorder traversal: In the process of preorder 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: Postorder traversal: In the process of postorder traversal, we will follow the leftright root policy. In this policy, we will recursively traverse all subtrees rooted in children. There are two subtrees: the left subtree and right subtree. So we will first traverse the left subtree, and then we will traverse the right subtree. Only after visiting all subtrees, we will visit the root. The name "postorder traverse" also refers to the root node coming after the left and right subtree. In the postorder traversal, the time complexity is also O(n). In the following form, we can represent the process of postorder traversal like this: In order traverse: In the process of inorder traversal, we will follow the leftrootright policy. In this policy, we will first traverse the left subtrees, then we will visit the root, and after that, we will traverse the right subtree. The name "inorder traverse" also refers to the root node will come between the left and right subtree. In inorder traversal, the time complexity is also O(n). In the following form, we can represent the process of in order traverse like this: 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 mary treesWe can store the m ary tree with the help of two ways: we can use an array, or we can use a pointerbased. Now we will explain them one by one like this: Array: Suppose we have a complete m ary tree. In this type of compact arrangement, if there is an index i, then we can find its cth child in range {1,...., m} with the help of its index m.i + c. In this case, this method wastes no space. In this type of method, the space complexity will be O(m^{n}). Pointerbased: There must be an internal array for each node so that this array can store pointers to each of its m children. The implementation method of pointerbased contains superior space complexity as compared to the arraybased implementation. So the space complexity of pointerbased method is O(m.n). Converting mary 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 worstcase 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 Mary treesThere are a lot of applications in the Mary tree, and some of them are described as follows:
In the following image, we will indicate an example of a grammar tree like this:
Next TopicMatrix in Discrete mathematics
