Data Structures and Algorithm: Binary Tree
Which of the choices is the correct answer?
The correct answer is:
1. AHGIFEBCD
The tree can be constructed as follow:
First we will take the information provided above which is the traversal details. So they are:
(i) Inorder: GHFIEABDC
(ii) Post Order: GFEIHDCBA
In the traversal of binary tree the alignment is as follows for different traversals:
(i) Inorder: Left-Node-Right (NLR)
(ii)Postorder: Left-Right-Node(LRN)
(iii) Preorder: Node-Left-Right (NLR)
So, the process constructing the binary tree will be step by step and can be done by
Step 1:
G |
H |
F |
I |
E |
A |
B |
D |
Here the complete inorder traversal is copied. Now we have to notice which node comes at the last in postorder traversal as in the post order node appears at the end.
Step 2:
As A node appears at the last of the post order traversal so the entire tree is divided into 2 halfs.
Step 3:
Before the node A the node B appears so the B will be the node and dc is placed on the right hand side of the B node.
Step 4:
In the post order traversal as the node C is precedent to D, the node C will be the parent node and D node will be the left child node of the C node.
Step 5:
After the construction of the right hand side of the binary tree H appears from the last after the node D so H will be parent node. In the inorder traversal the left part of the H node there is only G node so it will appear as a child node of H node. The right hand side of H will be constructed as it is in the inorder traversal.
Step 6:
From the node sequence FIE, it is clearly visible that in postorder traversal the node I appears at the last so I will be the parent node. In the inorder traversal In the left hand side of I, F is there so F will be the left child node of I and G will be the right child node of I. By following these steps the final tree is constructed by using the postorder and inorder traversal provided above.
For the preorder traversal we have to consider the node first then the left child and at last the right child. So in the above binary tree A is the root node so
(i) A
Then the left hand side of the tree where the root node is H so
(ii)AH
After that the left side of the H root node is G
(iii)AHG
As there is no nodes is left on the left hand side of H so after that the right hand side of the tree will be taken into consideration where the root node is I so
(iv)AHGI
After I the left and right hand side of the parent node I will be written and it will look alike
(v)AHGIFE
After completing the left hand side of the root node A the right hand side will be written. On the right hand side of root node A, the first node which appears is B so
(vi)AHGIFEB
As there is no left child node of B so the right child node C is taken so,
(vii)AHGIFEBC
There is only one node which is left in the entire binary tree so D will be attached to the traversal as
(viii)AHGIFEBCD
So the final preorder traversal of the binary tree is : AHGIFEBCD
Data Structures and Algorithm: Binary Tree Which of the choices is the correct answer? Given :...
c++, data structures Given the following Binary Tree: tree 56 47 69 22 49 59 11 29 62 I 23 30 61 64 1. Show the order in which the nodes in the tree are processed by inorder traversal, postorder traversal, and preorder traversal. 2. Show how the tree would look like after deletion of 29, 59 and 47 3. Show how the original tree would look after the insertion of nodes containing 63, 77,76, 48, 9, and 10 (in...
Data Structures and Algorithm: Binary Trees Which of the given choices is the right answer? Given the tree: F B A E н Get the infix of a tree. ABCDEFGHI ABCDEGFHI ABCDFGHIE IHGFEDCBA
Assume you are given “preorder” and “inorder” traversal result of a Binary Tree. Write an algorithm (pseudocode) that constructs the Binary Tree. For example, you can start with the Pre-Order and In-Order traversal of the same tree given below. Pre-Order = 80, 50, 10, 70, 100 In-Order = 10, 50, 70, 80, 100
1-Write an efficient algorithm to construct a binary tree from given inorder and postorder traversals.(java only). 2- Apply your proposed algorithm in the previous point to construct the binary tree with the following traversals (java code only): In order traversal: 9 8 6 1 2 5 4 Postorder traversal: 9 6 1 8 5 4 2
Data Structures and Algorithm: Trees Which of the choices is correct? Given the tree: F B А D E H Get the prefix of a tree. BFADCEGIH FDABCEGIH HIGECDABF FBADCEGIH
QUESTION 4 The shape of binary tree is unknown (unrelated to the tree defined in problem 3). However, we do have the following information: performing an inorder and a postorder traversals of the tree (containing nine integer nodes with integer values from 1 through 9) yield the following outputs: a) Inorder (LNR): 123456789 b) Postorder (LRN): 1354 2 8 796 Based on the above traversal information, determine the shape of the binary tree. Note that there is no need to...
LANGUAGE: C++ Write a class to create the binary tree (insert, delete, search, exit) and display the output using inorder, preorder and postorder tree traversal methods.
[Python] Construct Tree Using Inorder and Preorder Given Preorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root. Note: Assume binary tree contains only unique elements. Input format : Line 1 : n (Total number of nodes in binary tree) Line 2 : Pre order traversal Line 3 : Inorder Traversal Output Format : Elements are printed level wise, each level in new line...
this is java. Please find the answer The link structure of a binary tree can be uniquely determined by its Select one: a, inorder and preorder node sequences O b. preorder and postorder node sequences • postorder and levelorder node sequences O d. levelorder and inorder node sequences Clear my choice
There are generally considered to be four distinct binary tree traversals: preorder, inorder, postorder and level-order. Consider the following questions about these different kinds of traversals. Answer one of them that has not already been answered. What is the result of the various tree traversals when performed on an arithmetic expression tree? Which of the traversals are depth-first? Which are breadth-first? Which kind of traversal of a binary search tree produces the values in sorted order? Which of the traversals...