Implementation of the Binary Coding Scheme and the Tree Traversal Algorithms to Test for Ancestor- Descendant Relationships in K-ary Trees
نویسندگان
چکیده
This paper discusses the implementation of the binary coding scheme and its comparison with the post-order, preorder and in-order traversal techniques to test for ancestor-descendant relationships in k-ary trees (a tree in which any leaf node has up to k children). The approach used is assigning a unique binary code to each node in a tree. The value of the binary code for a node is the concatenation of the code for its parent node (referred to as prefix) and the unique binary representation of the immediate children of the parent node (referred to as suffix). For any two nodes I and J, if the binary code of node I forms the prefix of the code of node J, then node I is the ancestor for node J; otherwise not. This method to test ancestor-descendant relationships has a time complexity of O(1), whereas the tree-traversals incur a complexity of O(n).
منابع مشابه
Binary Codes for Fast Determination of Ancestor-Descendant Relationships in Trees
This paper proposes a new coding scheme and an algorithm to determine ancestordescendant relationship among nodes in a tree without tree traversal. Each node in a tree is assigned a unique binary code. The algorithm and the binary coding approach were tested with trees of different heights and widths. The algorithm is of O(1) complexity versus O(d) for tree traversal, where d is the depth of th...
متن کاملBinary Codes for Fast Determination of Ancestor-Descendant Relationship in Trees and Directed A-cyclic Graphs
This paper develops simple binary codes, called Binary Ancestry (BA) codes, for trees using which ancestor-descendant relationships among any two nodes of a tree can be determined without tree traversal. The BA coding technique assigns unique binary codes to each node of a tree. A procedure, IsAncestor, that uses BA codes to determine the relationships, yielded correct results in sample trees o...
متن کاملA novel algorithm to determine the leaf (leaves) of a binary tree from its preorder and postorder traversals
Binary trees are essential structures in Computer Science. The leaf (leaves) of a binary tree is one of the most significant aspects of it. In this study, we prove that the order of a leaf (leaves) of a binary tree is the same in the main tree traversals; preorder, inorder, and postorder. Then, we prove that given the preorder and postorder traversals of a binary tree, the leaf (leaves) of a bi...
متن کاملAn improved algorithm to reconstruct a binary tree from its inorder and postorder traversals
It is well-known that, given inorder traversal along with one of the preorder or postorder traversals of a binary tree, the tree can be determined uniquely. Several algorithms have been proposed to reconstruct a binary tree from its inorder and preorder traversals. There is one study to reconstruct a binary tree from its inorder and postorder traversals, and this algorithm takes running time of...
متن کاملAn improved algorithm to reconstruct a binary tree from its inorder and postorder traversals
It is well-known that, given inorder traversal along with one of the preorder or postorder traversals of a binary tree, the tree can be determined uniquely. Several algorithms have been proposed to reconstruct a binary tree from its inorder and preorder traversals. There is one study to reconstruct a binary tree from its inorder and postorder traversals, and this algorithm takes running time of...
متن کامل