Iterative Method for Recreating a Binary Tree from its Traversals (original) (raw)
Related papers
2012
Binary tree traversal refers to the process of visiting each node in a specified order. Given the inorder traversal of a binary tree, along with one of its preorder or postorder traversals, the original binary tree can be uniquely identified. Many recursive and non recursive method of construction of the tree from inorder and any of the postorder or preorder traversal have been proposed. In this paper one of the proposed algorithms has been examined. This algorithm computes the wrong tree for some input sequences. We show a particular situation in which the algorithm fails and a solution for this situation is proposed. The proposed a modified non-recursive algorithm for reconstructing a binary tree which generates the correct tree otherwise an error has been reported.
An improved algorithm to reconstruct a binary tree from its inorder and postorder traversals
2017
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 $ BigO{emph{n}^2} .Inthispaper,wepresent. In this paper, we present .Inthispaper,wepresent proc{InPos} $ an improved algorithm to reconstruct a binary tree from its inorder and postorder traversals. The running time and space complexity of the algorithm are an order of $ BigTheta{emph{n}} $ and $ BigTheta{emph{n}} $ respectively, which we prove to be optimal. The $ proc{InPos} $ algorithm not only reconstructs the binary tree, but also it determines different types of the nodes in a binary tree; nodes with two children, nodes with one child, and nodes with no child. At the end, the $ proc{InPos} $ returns a matrix-based structure t...
2011
This paper presents a new approach of reconstruction of Binary search tree using its Pre order tree-traversal only. There are many approaches given with the help of combination of two-tree traversals. But, in this paper we have not used any other combination of tree traversals to reconstruct the Binary search tree. Our work shows the implementation of this algorithm in C language. Our algorithm is found to be very simple and faster than other non recursive algorithms due to its unique implementation. Due to this reason the time and space complexities are significantly reduced.
A Note on the Reconstruction of a Binary Tree from its Traversals
Information Processing Letters, 1992
Gabrani, N. and P. Shankar, A note on the reconstruction of a binary tree from its traversals, Information Processing Letters 42 (1992) 117-119. We present a linear-time sequential algorithm for the construction of a binary tree, given its preorder and inorder traversals. The algorithm leads to an optimal O(log n) time parallel algorithm on the EREW PRAM model, where n is the number of nodes in the tree.
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 tree from its inorder and preorder traversals as well as inorder and postorder traversals. There is no study to focus on reconstructing a binary tree from both its preorder and postorder traversals. In this paper, we proved that given preorder and postorder traversals of a binary tree, the tree may not be identified uniquely, however, determining all the feasible solution(s) is possible. We present the PrePos algorithm, a novel algorithm to reconstruct all the possible binary tree(s) from its preorder and postorder traversals. PrePos algorithm not only finds the all the possible solutions, but also determines different types of the nodes in a binary tree; nodes with two children, nodes with one child, and node with no child. In the end, PrePos returns a matrix-based structure to represent all the binary tree solution(s). By this representation, the number of feasible solution can be counted in linear time.
A New Algorithm to Represent a Given k-ary Tree into Its Equivalent Binary Tree Structure
Journal of Physical Sciences, 2008
In this paper we have developed an algorithm that converts a given k-ary tree, for any k ≥ 3, to its equivalent binary tree structure. The binary tree is generated in O(n) time, for a k-ary tree with a total of n nodes. The algorithm is designed aiming at reducing the height of the constructed binary tree. The constructed tree does not contain any free links in the non-leaf nodes. That means the constructed tree is like a complete binary tree, where only leaves have no children, and nodes other than leaf nodes contain child (children) and some other valid information of the given k-ary tree.
Recursive and Nonrecursive Traversal Algorithms for Dynamically Created Binary Trees
The modeling of dynamical systems from a time series implemented by our DSA program introduces binary trees of height with all leaves on the same level, and the related subtrees of height L <= D. These are called epsilon-trees and epsilon-subtrees. The recursive and nonrecursive versions of the traversal algorithms for the trees with dynamically created nodes are discussed. The original nonrecursive algorithms that return the pointer to the next node in preorder, inorder and postorder traversals are presented. The space-time complexity analysis shows, and the execution time measurements confirm, that for these algorithms the recursive versions have approximately 10-25% better time constants. Still, the use of nonrecursive algorithms may be more appropriate in several occasions.