Inorder and preorder traversal to reconstruct a binary tree, Data Structure & Algorithms

Assignment Help:

Q. Using the following given inorder and preorder traversal reconstruct a binary tree

Inorder sequence is

D, G, B, H, E, A, F, I, C


Preorder sequence is

A, B, D, G, E, H, C, F, I

 

Ans:

The In-order sequence given to us is :- D, G, B, H, E, A, F, I, C

Pre-order sequence given to us is:- A, B, D, G, E, H, C, F, I

The binary tree T is drawn from its root downward by selecting the first node in its pre-order as root of T then study the left and right child recursively. The tree T is drawn below:

 

 

1354_Binary Tree.png


Related Discussions:- Inorder and preorder traversal to reconstruct a binary tree

Data structure queue, In this unit, we described about the data structure Q...

In this unit, we described about the data structure Queue. It had two ends. One is front from where the elements can be removed and the other is rear where the elements can be inse

Algorithm to delete node from binary search tree, Normal 0 fals...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Create a function to show data structure, Given a number that is represente...

Given a number that is represented in your data structure, you will need a function that prints it out in base 215 in such a way that its contents can be checked for correctness. Y

Addressing modes, Compare zero-address, one-address, two-address, and three...

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

State warnock algorithm, Warnock's Algorithm An interesting approach to...

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Determine the types of java, Determine the types of JAVA Java has two p...

Determine the types of JAVA Java has two parts... 1. Core language -- variables, arrays, objects o Java Virtual Machine (JVM) runs the core language o Core language is

Find the optimal control, 1. Use the Weierstrass condition, find the (Stron...

1. Use the Weierstrass condition, find the (Strongly) minimizing curve and the value of J min for the cases where x(1) = 0, x(2) = 3. 2. The system = x 1 + 2u; where

Finite automata, find the grammar of regular expression of (a/?)(a/b)?

find the grammar of regular expression of (a/?)(a/b)?

Last in first out method, This method is the reverse of FIFO and assumes th...

This method is the reverse of FIFO and assumes that each issue of stock is made from latest items received in the enterprises .Thus if the last lot to be received is not sufficient

Example of single node with multiple elements, The class Element represents...

The class Element represents a single node that can be part of multiple elements on a hotplate and runs in its own thread. The constructor accepts the initial temperature and a hea

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd