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

Traversal tree program in c/c++
Traversal tree program in c/c++
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]
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...
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...
Consider the following demand curve: A B C D E F G H I J P...
Consider the following demand curve: A B C D E F G H I J P $0.50 $0.45 $0.40 $0.35 $0.30 $0.25 $0.20 $0.15 $0.10 $0.05 QD 1 2 4 6 9 12 16 20 25 30 Calculate elasticities for pairs of points to check statements that were made during class and in the text. When making the calculations, use average price and average quantity for the two points. The formula for this should be in your notes. It is...
Let S denote the 10-element set {a,b,c,d,e,f,g,h,i,j}. How many ways can we construct a subset of...
Let S denote the 10-element set {a,b,c,d,e,f,g,h,i,j}. How many ways can we construct a subset of S of size 7 ? 120 How many ways can we construct a subset of S of size 7 containing the element j? 84 How many ways can we construct a subset of S of size 7 containing i but not j ? 28 How many ways can we construct a subset of S of size 7 containing h but neither i nor j...
Consider the relation R= {A, B, C, D, E, F, G, H} and the set of...
Consider the relation R= {A, B, C, D, E, F, G, H} and the set of functional dependencies: FD= {{B}—> {A}, {G}—> {D, H}, {C, H}—> {E}, {B, D}—> {F}, {D}—>{C}, {C}—> {G}} 1) Draw FD using the diagrammatic notation. 2) What are all candidate keys for R? 3) If delete {C}—>{G} and change {C, H}—> {E} to {C, H}—> {E, G}, what are all candidate keys for R
Let G = Z4 × Z4, H = ⟨([2]4, [3]4)⟩. (a) Find a,b,c,d∈G so that G...
Let G = Z4 × Z4, H = ⟨([2]4, [3]4)⟩. (a) Find a,b,c,d∈G so that G is the disjoint union of the 4 cosets a+H,b+ H, c + H, d + H. List the elements of each coset. (b) Is G/H cyclic?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT