Question

In: Computer Science

P1. Construct the tree with post-order traversal string = i b d a h g c...

P1. Construct the tree with post-order traversal string = i b d a h g c f, and in-order traversal string = b i a d f g h c.

P2. Construct the tree with pre-order traversal string = 10, 20, 40, 50, 80, 60, 70, 90, and in-order traversal string = 40, 50, 20, 10, 80, 70, 90, 60.

Solutions

Expert Solution

P1. Postoder traversal = (Left node, Right Node,Root Node)

And in the Inorder traversal :

First ->Left node.

The center part -> Root node.

The Last -> Right node.

Now given Post order traversal = i b d a h g c f

And the Inorder traversal = b i a d f g h c

Step1: First Find the Root node from Post order traversal i.e first element from right.

Step2:From Inorder,The nodes at left->Left nodes and The nodes at Right->Right nodes

Step3:From the Post order check which node comes first when traversed from right end to left end. The first coming element will be the next root node.

Step4:obtain the Left node and Right node from the provided inorder traversal string.

Step 5: Repeat steps 1 to 4 until there is no nodes to be covered .

After computing the Tree obtained will be:

P2. Preoder traversal = (Root node, Left Node,Right Node)

And in the In order traversal the order of nodes is:

First comes the Left node.

The center part ->Root node.

The Last part will be the Right node.

Now given Pre order traversal = 10,20,40,50,80,60,70,90

And the Inorder traversal = 40,50,20,10,80,70,90,60

Step1: First Find the Root node from Pre order traversal i.e first element from left.

Step2:From Inorder,The nodes at left->Left nodes and The nodes at Right->Right nodes

Step3:From the Pre order check which node comes first when traversed from left end to the right end of string. The first coming element will be the next root node.

Step4:Get the left node and right node from the provided inorder string.

Step 5: Repeat steps 1 to 4 until there is no nodes to be covered.

After computing the Tree obtained will be:

Hope it helps!!!


Related Solutions

1. Create the binary tree that has postorder traversal of { b d a h g...
1. Create the binary tree that has postorder traversal of { b d a h g c f,} and has the inorder traversal of {b i a d f g h c} 2. Create the binary tree that has the preorder traversal of {10, 20, 40, 50, 80, 60, 70, 90} and the inorder traversal of { 40, 50, 20, 10, 80, 70, 90, 60}
Tree Reconstruction - Pre+In => Post (C++) Give you pre-order traversal and in-order traversal, please output...
Tree Reconstruction - Pre+In => Post (C++) Give you pre-order traversal and in-order traversal, please output post-order traversal. Input Two lines. Pre-order traversal and in-order traversal. Output Post-order traversal. Sample Input GDAFEMHZ ADEFGHMZ Sample Output AEFDHZMG
Create a Binary Search Tree for the following data and do In-order, Preorder and Post-order traversal...
Create a Binary Search Tree for the following data and do In-order, Preorder and Post-order traversal of the tree. 50, 60, 25, 40, 30, 70, 35, 10, 55, 65, 5 Write an algorithm to delete a node in Singly Linked List                            [12 Write an algorithm of Binary Search                                                              [10] Write a program in ‘C’ to generate Fibonacci series using recursion            [8]
Traversal tree program in c/c++
Traversal tree program in c/c++
Design a nonrecursive post order traversal algorithm. 1.Use the linked representation for the binary tree to...
Design a nonrecursive post order traversal algorithm. 1.Use the linked representation for the binary tree to be traversed. 2.Except left, right, and data fields, there are no other fields in a node. 3.After the traversal the tree should remain intact. 4.Use only one stack. 5.You can’t push anything other than nodes into the stack.
Please fill in the blanks (values of A, B, C, D, E, F, G, H, I...
Please fill in the blanks (values of A, B, C, D, E, F, G, H, I , J) for the following financial statements. The firm’s tax rate is 35.3%. Income Statement for Fiscal Year 2015 Sales 2,000 Cost of goods sold 1,500 Gross margin 500 Selling and general expenses 300 Operating income 200 Interest income 5 205 Interest expense 21 Restructuring charges 14 Income before tax 170 Income tax 60 Net income J Balance Sheet, Year 2014 and Year 2015...
Modifying the tree traversal C program shown below to do reversed tree traversal as defined below....
Modifying the tree traversal C program shown below to do reversed tree traversal as defined below. Reversed PreOrder: Root, Right, Left. Reversed InOrder:     Right, Root, Left. Reversed PostOrder: Right, Left, Root. The tree is: Root = 1, Left(1) = -2, Right(1) = -3; Left(-2) = 4, Right(-2) = 5; Left(-3) = 6, Right(-3)= 7; Left(5) = -8, Right(5)= -9; Left(7) = 10, Right(7) = 11; Left(11) = -12, Right(11) = -13; Left(-13) = 14. Your program should output the printed...
How many proper subsets are there for this set {A,B,C,D,E,F,G,H,I}?
How many proper subsets are there for this set {A,B,C,D,E,F,G,H,I}?
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4....
1. ¬B∨(G↔J), H→(B&C) ∴(H&J)→G 2. A∨B, C↔¬(B∨D) ∴C→A 3. (A&B) ↔ (F→G), (A&F) & B∴(G→R)→R 4. T→¬B, T→¬D ∴ T→¬(B∨D) 5. ¬(M∨¬S), S→(R→M) ∴A → (¬R∨T) 6. (F&G) → I, (I∨J) → K ∴F→(G→K) 7. ¬U, O→G, ¬(O∨G) →U ∴G Prove that the arguments are valid by constructing a dedication using the rules MP, MT, DN, Conj, Simp, CS, Disj, DS, DM, CP, HS, BE, and DL. Use CP if needed.
Consider the following bivariate data. Point A B C D E F G H I J...
Consider the following bivariate data. Point A B C D E F G H I J x 0 1 1 2 3 4 5 6 6 7 y 5 5 6 5 4 3 2 0 1 1 (a) Construct a scatter diagram of the given bivariate data. (Do this on paper. Your instructor may ask you to turn in this work.) (b) Calculate the covariance. (Give your answer correct to two decimal places.) (c) Calculate sx and sy. (Give...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT