0% found this document useful (0 votes)
974 views

Construct The Binary Tree From Preorder and Inorder

Given a preorder sequence of A B C D E F G H I and an inorder sequence of B C A E D G H F I, the binary tree can be constructed as follows: A is the root node since it is first in the preorder sequence; B and C are left subtree nodes and D through I are right subtree nodes based on the inorder sequence; the tree is then constructed recursively using the subtrees defined by the inorder sequence and the nodes in the preorder sequence.

Uploaded by

Sarthak Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
974 views

Construct The Binary Tree From Preorder and Inorder

Given a preorder sequence of A B C D E F G H I and an inorder sequence of B C A E D G H F I, the binary tree can be constructed as follows: A is the root node since it is first in the preorder sequence; B and C are left subtree nodes and D through I are right subtree nodes based on the inorder sequence; the tree is then constructed recursively using the subtrees defined by the inorder sequence and the nodes in the preorder sequence.

Uploaded by

Sarthak Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Construct The Binary Tree from Preorder and

Inorder Sequence
Every binary tree has a unique pair of preorder /
inorder sequences.

Give preorder and inorder sequence as follows.


preorder sequence A B C D E F G H I
Inorder sequence B C A E D G H F I

Use the preorder sequence to find the root


Use the inorder sequence to find the nodes in
left and right subtrees

Prof. Gayathri. P, SCSE, VIT University

Construct The Binary Tree from Preorder and


Inorder Sequence
A

A
EDGHFI

B C

D
C

G
B

D, E, F, G, H, I

C
Prof. Gayathri. P, SCSE, VIT University

You might also like