SlideShare a Scribd company logo
Creating a Binary tree from
a GeneralTree
S.DEEPA
Assistant Professor(Sr.G)
Department of ComputerTechnology – PG
Kongu Engineering College
• The rules for converting a general tree to a binary tree are
Rule 1: Root of the binary tree = Root of the general tree
Rule 2: Left child of a node in the binary tree = Leftmost child of the node
in the general tree
Rule 3: Right child of a node in the binary tree = Right sibling of the node in
the general tree
Now let us build the binary tree.
• Step 1: Node A is the root of the general tree, so it will also be
the root of the binary tree.
• Step 2: Left child of node A is the leftmost child of node A in
the general tree and right child of node A is the right sibling of
the node A in the general tree. Since node A has no right
sibling in the general tree, it has no right child in the binary
tree.
• Step 3: Now process node B. Left child of B is E and its right
child is C (right sibling in general tree).
• Step 4: Now process node C. Left child of C is F
(leftmost child) and its right child is D (right
sibling in general tree).
• Step 5: Now process node D. Left child of D is I
(leftmost child). There will be no right child of D
because it has no right sibling in the general
tree.
• Step 6: Now process node I. There will be no left
child of I in the binary tree because I has no left
child in the general tree. However, I has a right
sibling J, so it will be added as the right child of I.
• Step 7: Now process node J. Left child of J is K
(leftmost child). There will be no right child of J
because it has no right sibling in the general
tree.
• Step 8: Now process all the unprocessed nodes
(E, F, G, H, K) in the same fashion, so the
resultant binary tree can be given as follows.
TRAVERSING A BINARYTREE
• Traversing a binary tree is the process of visiting each node in the tree
exactly once in a systematic way.
• Unlike linear data structures in which the elements are traversed
sequentially, tree is a nonlinear data structure in which the elements can be
traversed in many different ways.
• There are different algorithms for tree traversals. These algorithms differ in
the order in which the nodes are visited.
Pre-orderTraversal
• To traverse a non-empty binary tree in pre-order, the following operations are
performed recursively at each node.The algorithm works by:
1.Visiting the root node,
2.Traversing the left sub-tree, and finally
3.Traversing the right sub-tree.
• Consider the tree given in Fig. 9.15. The pre-order traversal of the tree is given as A,
B, C.
• Root node first, the left sub-tree next, and then the right sub-tree. Pre-order
traversal is also called as depth-first traversal.
• In this algorithm, the left sub-tree is always traversed before the right sub-tree.
• The word ‘pre’ in the pre-order specifies that the root node is accessed prior to any
other nodes in the left and right sub-trees.
• Pre-order algorithm is also known as the NLR traversal algorithm (Node-Left-
Right).
• Pre-order traversal algorithms are used to extract a prefix notation from an
expression tree.
In-orderTraversal
• To traverse a non-empty binary tree in in-order, the following operations are
performed recursively at each node.
• The algorithm works by:
1.Traversing the left sub-tree,
2.Visiting the root node, and finally
3.Traversing the right sub-tree.
• Consider the tree given in Fig. 9.15.The in-order traversal of the tree is given as B,
A, and C.
• Left sub-tree first, the root node next, and then the right sub-tree. In-order
traversal is also called as symmetric traversal.
• In this algorithm, the left sub-tree is always traversed before the root node and the
right sub-tree.
• The word ‘in’ in the in-order specifies that the root node is accessed in between the
left and the right sub-trees. In-order algorithm is also known as the LNR traversal
algorithm (Left-Node-Right).
• In-order traversal algorithm is usually used to display the elements of a
binary search tree.
• Here, all the elements with a value lower than a given value are accessed
before the elements with a higher value.
Post-orderTraversal
• To traverse a non-empty binary tree in post-order, the following operations are performed recursively at each
node.The algorithm works by:
1.Traversing the left sub-tree,
2.Traversing the right sub-tree, and finally
3.Visiting the root node.
• Consider the tree given in Fig. 9.18.The post-order traversal of the tree is given as B, C andA.
• Left sub-tree first, the right sub-tree next, and finally the root node.
• In this algorithm, the left sub-tree is always traversed before the right sub-tree and the root node.
• The word ‘post’ in the post-order specifies that the root node is accessed after the left and the right sub-trees.
• Post-order algorithm is also known as the LRN traversal algorithm (Left-Right-Node).
• Post-order traversals are used to extract postfix notation from an expression tree.
Level-orderTraversal
• In level-order traversal, all the nodes at a level are accessed before going to
the next level.
• This algorithm is also called as the breadth-first traversal algorithm.
Constructing a BinaryTree fromTraversal
Results
• We can construct a binary tree if we are given at least two traversal results.
• The first traversal must be the in-order traversal and the second can be either pre-
order or post-order traversal.
• The in-order traversal result will be used to determine the left and the right child
nodes, and the pre-order/post-order can be used to determine the root node.
• For example, consider the traversal results given below:
• In–orderTraversal: D B E A F C G Pre–orderTraversal: A B D E C F G
• Here, we have the in-order traversal sequence and pre-order traversal sequence.
Steps to construct tree
• Step 1 Use the pre-order sequence to determine the root node of the tree.
The first element would be the root node.
• Step 2 Elements on the left side of the root node in the in-order traversal
sequence form the left sub-tree of the root node. Similarly, elements on the
right side of the root node in the in-order traversal sequence form the right
sub-tree of the root node.
• Step 3 Recursively select each element from pre-order traversal sequence
and create its left and right sub-trees from the in-order traversal sequence.
• Look at below image which constructs the tree from its traversal results.
• Now consider the in-order traversal and post-order traversal sequences of a given binary
tree.
• Before constructing the binary tree, remember that in post-order traversal the root node is
the last node.
Creating a Binary tree from a General Tree.pptx

More Related Content

What's hot

Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Stack
StackStack
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
Adam Mukharil Bachtiar
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
SIVASHANKARIRAJAN
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Queues
QueuesQueues
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
Stacks
StacksStacks
Stacks
sweta dargad
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Binary tree
Binary  treeBinary  tree
Binary tree
Vanitha Chandru
 
Data Structures
Data StructuresData Structures
Data Structures
Prof. Dr. K. Adisesha
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
Trupti Agrawal
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 

What's hot (20)

Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Stack
StackStack
Stack
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Linked list
Linked listLinked list
Linked list
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Queues
QueuesQueues
Queues
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Stacks
StacksStacks
Stacks
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Data Structures
Data StructuresData Structures
Data Structures
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 

Similar to Creating a Binary tree from a General Tree.pptx

Binary tree
Binary treeBinary tree
Binary tree
MKalpanaDevi
 
Tree
TreeTree
Tree
sbkbca
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
Sana Yameen
 
Tree
TreeTree
Binary tree
Binary treeBinary tree
Binary tree
Afaq Mansoor Khan
 
Tree traversal techniques
Tree traversal  techniquesTree traversal  techniques
Tree traversal techniques
Mudita Srivastava
 
Basics of Binary Tree and Binary Search Tree.pptx
Basics of Binary Tree and Binary Search Tree.pptxBasics of Binary Tree and Binary Search Tree.pptx
Basics of Binary Tree and Binary Search Tree.pptx
BhagyashriKotame2
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
Dr.Umadevi V
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
rupanaveen24
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
zia eagle
 
Trees
TreesTrees
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
ER Punit Jain
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
Anusruti Mitra
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
LavanyaJ28
 
Advanced c c++
Advanced c c++Advanced c c++
Advanced c c++
muilevan
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
KamranAli649587
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 

Similar to Creating a Binary tree from a General Tree.pptx (20)

Binary tree
Binary treeBinary tree
Binary tree
 
Tree
TreeTree
Tree
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Tree
TreeTree
Tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Tree traversal techniques
Tree traversal  techniquesTree traversal  techniques
Tree traversal techniques
 
Basics of Binary Tree and Binary Search Tree.pptx
Basics of Binary Tree and Binary Search Tree.pptxBasics of Binary Tree and Binary Search Tree.pptx
Basics of Binary Tree and Binary Search Tree.pptx
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
Trees
TreesTrees
Trees
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Advanced c c++
Advanced c c++Advanced c c++
Advanced c c++
 
lecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminologylecture10 date structure types of graph and terminology
lecture10 date structure types of graph and terminology
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
 

More from DeepaThirumurugan

APACHE SPARK.pptx
APACHE SPARK.pptxAPACHE SPARK.pptx
APACHE SPARK.pptx
DeepaThirumurugan
 
IO organization.ppt
IO organization.pptIO organization.ppt
IO organization.ppt
DeepaThirumurugan
 
Difference between traditional and agile software development
Difference between traditional and agile software developmentDifference between traditional and agile software development
Difference between traditional and agile software development
DeepaThirumurugan
 
Agile Development Models
Agile Development ModelsAgile Development Models
Agile Development Models
DeepaThirumurugan
 
Cloud Computing
Cloud Computing Cloud Computing
Cloud Computing
DeepaThirumurugan
 
Data structures - Introduction
Data structures - IntroductionData structures - Introduction
Data structures - Introduction
DeepaThirumurugan
 

More from DeepaThirumurugan (6)

APACHE SPARK.pptx
APACHE SPARK.pptxAPACHE SPARK.pptx
APACHE SPARK.pptx
 
IO organization.ppt
IO organization.pptIO organization.ppt
IO organization.ppt
 
Difference between traditional and agile software development
Difference between traditional and agile software developmentDifference between traditional and agile software development
Difference between traditional and agile software development
 
Agile Development Models
Agile Development ModelsAgile Development Models
Agile Development Models
 
Cloud Computing
Cloud Computing Cloud Computing
Cloud Computing
 
Data structures - Introduction
Data structures - IntroductionData structures - Introduction
Data structures - Introduction
 

Recently uploaded

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 

Recently uploaded (20)

Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 

Creating a Binary tree from a General Tree.pptx

  • 1. Creating a Binary tree from a GeneralTree S.DEEPA Assistant Professor(Sr.G) Department of ComputerTechnology – PG Kongu Engineering College
  • 2. • The rules for converting a general tree to a binary tree are Rule 1: Root of the binary tree = Root of the general tree Rule 2: Left child of a node in the binary tree = Leftmost child of the node in the general tree Rule 3: Right child of a node in the binary tree = Right sibling of the node in the general tree
  • 3. Now let us build the binary tree. • Step 1: Node A is the root of the general tree, so it will also be the root of the binary tree. • Step 2: Left child of node A is the leftmost child of node A in the general tree and right child of node A is the right sibling of the node A in the general tree. Since node A has no right sibling in the general tree, it has no right child in the binary tree. • Step 3: Now process node B. Left child of B is E and its right child is C (right sibling in general tree).
  • 4. • Step 4: Now process node C. Left child of C is F (leftmost child) and its right child is D (right sibling in general tree). • Step 5: Now process node D. Left child of D is I (leftmost child). There will be no right child of D because it has no right sibling in the general tree. • Step 6: Now process node I. There will be no left child of I in the binary tree because I has no left child in the general tree. However, I has a right sibling J, so it will be added as the right child of I.
  • 5. • Step 7: Now process node J. Left child of J is K (leftmost child). There will be no right child of J because it has no right sibling in the general tree. • Step 8: Now process all the unprocessed nodes (E, F, G, H, K) in the same fashion, so the resultant binary tree can be given as follows.
  • 6. TRAVERSING A BINARYTREE • Traversing a binary tree is the process of visiting each node in the tree exactly once in a systematic way. • Unlike linear data structures in which the elements are traversed sequentially, tree is a nonlinear data structure in which the elements can be traversed in many different ways. • There are different algorithms for tree traversals. These algorithms differ in the order in which the nodes are visited.
  • 7. Pre-orderTraversal • To traverse a non-empty binary tree in pre-order, the following operations are performed recursively at each node.The algorithm works by: 1.Visiting the root node, 2.Traversing the left sub-tree, and finally 3.Traversing the right sub-tree. • Consider the tree given in Fig. 9.15. The pre-order traversal of the tree is given as A, B, C. • Root node first, the left sub-tree next, and then the right sub-tree. Pre-order traversal is also called as depth-first traversal.
  • 8. • In this algorithm, the left sub-tree is always traversed before the right sub-tree. • The word ‘pre’ in the pre-order specifies that the root node is accessed prior to any other nodes in the left and right sub-trees. • Pre-order algorithm is also known as the NLR traversal algorithm (Node-Left- Right). • Pre-order traversal algorithms are used to extract a prefix notation from an expression tree.
  • 9.
  • 10.
  • 11. In-orderTraversal • To traverse a non-empty binary tree in in-order, the following operations are performed recursively at each node. • The algorithm works by: 1.Traversing the left sub-tree, 2.Visiting the root node, and finally 3.Traversing the right sub-tree. • Consider the tree given in Fig. 9.15.The in-order traversal of the tree is given as B, A, and C. • Left sub-tree first, the root node next, and then the right sub-tree. In-order traversal is also called as symmetric traversal. • In this algorithm, the left sub-tree is always traversed before the root node and the right sub-tree. • The word ‘in’ in the in-order specifies that the root node is accessed in between the left and the right sub-trees. In-order algorithm is also known as the LNR traversal algorithm (Left-Node-Right).
  • 12. • In-order traversal algorithm is usually used to display the elements of a binary search tree. • Here, all the elements with a value lower than a given value are accessed before the elements with a higher value.
  • 13.
  • 14. Post-orderTraversal • To traverse a non-empty binary tree in post-order, the following operations are performed recursively at each node.The algorithm works by: 1.Traversing the left sub-tree, 2.Traversing the right sub-tree, and finally 3.Visiting the root node. • Consider the tree given in Fig. 9.18.The post-order traversal of the tree is given as B, C andA. • Left sub-tree first, the right sub-tree next, and finally the root node. • In this algorithm, the left sub-tree is always traversed before the right sub-tree and the root node. • The word ‘post’ in the post-order specifies that the root node is accessed after the left and the right sub-trees. • Post-order algorithm is also known as the LRN traversal algorithm (Left-Right-Node). • Post-order traversals are used to extract postfix notation from an expression tree.
  • 15.
  • 16. Level-orderTraversal • In level-order traversal, all the nodes at a level are accessed before going to the next level. • This algorithm is also called as the breadth-first traversal algorithm.
  • 17. Constructing a BinaryTree fromTraversal Results • We can construct a binary tree if we are given at least two traversal results. • The first traversal must be the in-order traversal and the second can be either pre- order or post-order traversal. • The in-order traversal result will be used to determine the left and the right child nodes, and the pre-order/post-order can be used to determine the root node. • For example, consider the traversal results given below: • In–orderTraversal: D B E A F C G Pre–orderTraversal: A B D E C F G • Here, we have the in-order traversal sequence and pre-order traversal sequence.
  • 18. Steps to construct tree • Step 1 Use the pre-order sequence to determine the root node of the tree. The first element would be the root node. • Step 2 Elements on the left side of the root node in the in-order traversal sequence form the left sub-tree of the root node. Similarly, elements on the right side of the root node in the in-order traversal sequence form the right sub-tree of the root node. • Step 3 Recursively select each element from pre-order traversal sequence and create its left and right sub-trees from the in-order traversal sequence.
  • 19. • Look at below image which constructs the tree from its traversal results. • Now consider the in-order traversal and post-order traversal sequences of a given binary tree. • Before constructing the binary tree, remember that in post-order traversal the root node is the last node.