International Journal of Computer Applications |
Foundation of Computer Science (FCS), NY, USA |
Volume 57 - Number 11 |
Year of Publication: 2012 |
Authors: Nitin Arora, Pradeep Kumar Kaushik, Satendra Kumar |
10.5120/9156-2056 |
Nitin Arora, Pradeep Kumar Kaushik, Satendra Kumar . Iterative Method for Recreating a Binary Tree from its Traversals. International Journal of Computer Applications. 57, 11 ( November 2012), 6-13. DOI=10.5120/9156-2056
Many reconstruction algorithms for binary tree have been discussed in this paper. A particular focus of this paper is on "A new Non-Recursive Algorithm for Reconstructing a Binary Tree from its Traversals". The computation time required for executing the reconstruction algorithm are O(N) and space complexity is O(NlogN) where N is the number of nodes in the binary tree. This algorithm works well for most of the input cases, but it has some drawbacks. There are some sequences of pre-order and in-order for which no legitimate tree can be constructed but the algorithm didn't take these cases into consideration and constructed a wrong tree for these cases. In this paper, we have proposed a solution to the problem in the previous algorithm and designed an algorithm which is the modified version of the previous algorithm for generating a correct binary tree. The new modified algorithm is implemented in C language and tested in GCC Compiler in Linux, for all types of input cases. The New modified algorithm works well for all types of input cases. We have calculated the best case time complexity of modified algorithm and show that a correct tree can be reported in O(N) time in best case and O(NlogN) space where N is the number of nodes in the tree. We have discussed some applications of the new modified algorithm in Huffman Coding, compiler design, text processing and searching algorithms.