Level-Order Sequential Representation Converting from Sequential to Link Representation

J.E.D.I and internally represented as:

5.4.3.3 Level-Order Sequential Representation

The third option in sequential representation is level-order. In this representation, the forest is traversed in level-order, i.e., top-to-bottom, left-to-right, to obtain the level- order listing of elements. Just like family-order, brothers which constitute a family are listed consecutively. LLINK and RTAG are used in the representation. LLINK is a pointer to the oldest son in the forest or the left son in its binary tree representation. RTAG identifies the youngest brother in a brood or the last member of the family. Using level-order sequential representation, we have the following for the forest F: Notice that unlike preorder and family-order, arrows cross in this representation. However, it can also be noticed that the first arrow to begin is also the first arrow to end. Having the FIFO first-in, first-out structure, queue could be used to establish a relation between nodes. Therefore, just like the previous methods, it could be represented as:

5.4.3.4 Converting from Sequential to Link Representation

Spacewise, sequential representation is good for forests. However, since link representation is more natural for forests, there are instances that we have to use the latter. The following is a method that implements the conversion from sequential to linked representation: Data Structures 81 J.E.D.I Converts this forest into its binary tree representation BinaryTree convert{ BinaryTree t = new BinaryTree; BTNode alpha = new BTNode; LinkedStack stack = new LinkedStack; BTNode sigma; BTNode beta; Set up root node t.root = alpha; Generate the rest of the binary tree for int i=0; in-1; i++{ alpha.info = INFO[i]; beta = new BTNode; if with right son, push – will build the right subtree later if RTAG[i] == 1 stack.pushalpha; else alpha.right = null; if leaf node, pop if LTAG[i] == 1{ alpha.left = null; sigma = BTNode stack.pop; sigma.right = beta; } else alpha.left = beta; alpha.info = INFO[i]; alpha = beta; } Fill in fields of the rightmost node alpha.info = INFO[n-1]; return t; } Data Structures 82 J.E.D.I

5.5 Arithmetic Tree Representations