SlideShare a Scribd company logo
Data Structures
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Information Technology
(NBAAccredited)
Ms. K. D. Patil
Assistant Professor
Tree
• General Trees, Tree Terminology, Binary Trees, Use binary trees,
Conversion of general tree to binary tree, Array Based
representation of Binary Tree, Binary tree as an ADT, Binary tree
traversals - recursive and non-recursive algorithms, Construction
of tree from its traversals, Huffman coding algorithm
Data Structures Mrs. Kanchan Patil Department of Information Technology
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Let’s consider a Binary tree of 7 nodes
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• For the array representation of binary tree, we have to give numbering
to the corresponding nodes.
• Start from the root node and move from left to right at every level.
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• we have numbered from zero you can simply place the corresponding
number in the matching index of an array.
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Now Let’s consider a Binary tree
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Make the child node of the leaf nodes as NULL
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Now number the nodes as done above for the array representation of
binary tree.
Array Based Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• we have numbered from zero you can simply place the corresponding
number in the matching index of an array.
Linked List Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• We use a double linked list to represent a binary tree. In a double linked
list, every node consists of three fields.
• First field for storing left child address, second for storing actual data and
third for storing right child address.
Linked List Representation of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
Binary Tree as an ADT
• Binary Tree have a maximum of two children
• we can assign direct pointers to them
• The declaration of tree nodes is same as in structure to that for doubly linked lists,
in that a node is a structure including the key information plus two pointers (left and
right) to other nodes
• Binary Tree node declaration
class Node {
int value;
Node left;
Node right;
Node(int value) {
this.value = value;
right = null;
left = null;
}
}
Binary Tree as an ADT
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Binary Tree class declaration
class binary_tree
{ node left, right;
public:
btree()
{
root=NULL;
}
Isempty();
void create();
void display();
void insert(node,node);
void inorder(node);
void longestPath();
int depth(node);
void display_leaves(node temp);
node copy(node first);
void copytree();
};
General Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• A General Tree is a tree in which each node can have an unlimited out-degree
• Each node may have as many children as is necessary to satisfy its requirements
• It is also referred as N-array tree
• Examples:
Changing General Tree to Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• A General Tree we can use following two relations
• Parent to Child
• Sibling to Sibling
• Rules are as follows:
• The root of the Binary Tree is the Root of the Generic Tree
• The left child of a node in the Generic Tree is the Left child of that node in the
Binary Tree
• The right sibling of any node in the Generic Tree is the Right child of that node in
the Binary Tree
Changing General Tree to Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Steps to Convert General Tree to Binary Tree
• Step I:
• Identify the branch from parent to its first and leftmost child
• Step II:
• Connect siblings starting with leftmost child using a branch for each siblings to
its right siblings.
• Step III:
• Remove all unneeded branches from the parent to its children. You will get the
final binary tree
Example
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Step I:
• Identify the branch from parent to its first and
leftmost child
• Step II:
• Connect siblings starting with leftmost child using
a branch for each siblings to its right siblings.
• Step III:
• Remove all unneeded branches from the parent
to its children. You will get the final binary tree
Example
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Final Binary Tree:
Quiz..
Data Structures Mrs. Kanchan Patil Department of Information Technology
Quiz..
Data Structures Mrs. Kanchan Patil Department of Information Technology
Inserting into General Trees
Data Structures Mrs. Kanchan Patil Department of Information Technology
• To insert a node into a general tree, the user must supply the parent of the
node.
• The new node can be inserted using 3 different ways:
• FIFO insertion
• LIFO insertion
• Key sequenced insertion
Inserting into General Trees
Data Structures Mrs. Kanchan Patil Department of Information Technology
• FIFO insertion:
• Insert a node at the end of the sibling list as we insert a node at the rear of
a queue
Inserting into General Trees
Data Structures Mrs. Kanchan Patil Department of Information Technology
• LIFO insertion:
• Insert a node at the beginning of the sibling list
Inserting into General Trees
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Key sequenced insertion:
• Places the new node in key sequence among the sibling nodes
• It is most common insertion rule in general trees
• It is similar to the insertion rule in a general ordered linked list
References
Data Structures Mrs. Kanchan Patil Department of Information Technology
• R. Lafore, “Data structures and Algorithms in Java”, Pearson education, ISBN: 9788
131718124.
• Michael Goodrich, Roberto Tamassia, Michael H. Goldwasser, “Data Structures and
Algorithms in Java”, 6th edition, wiley publication, ISBN: 978-1-118-77133-4
• R. Gilberg, B. Forouzan, “Data Structure: A Pseudo code approach with C++”, Cengage
Learning.
• Sartaj Sahni, “Data Structures, Algorithms and Applications in C++”, 2 nd Edition,
Universities Press.
• E. Horowitz, S. Sahni, S. Anderson-freed, “Fundamentals of Data Structures in C”, 2 nd
Edition, University Press, ISBN 978-81-7371-605-8.
Data Structures Mrs. Kanchan Patil Department of Information Technology
Thank You!!!
Happy Learning!!!

More Related Content

Similar to Unit 2_2 Binary Tree as ADT_General Tree.pdf

Data Structures and Algorithm - Week 4 - Trees, Binary Trees
Data Structures and Algorithm - Week 4 - Trees, Binary TreesData Structures and Algorithm - Week 4 - Trees, Binary Trees
Data Structures and Algorithm - Week 4 - Trees, Binary Trees
Ferdin Joe John Joseph PhD
 
Advanced c c++
Advanced c c++Advanced c c++
Advanced c c++
muilevan
 
SIX WEEKS SUMMER TRAINING REPORT.pptx
SIX WEEKS SUMMER TRAINING REPORT.pptxSIX WEEKS SUMMER TRAINING REPORT.pptx
SIX WEEKS SUMMER TRAINING REPORT.pptx
sagabo1
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
SelshaCs
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
Data model
Data modelData model
Data model
RUpaliLohar
 
Unit 2_3 Binary Tree Traversals.pdf
Unit 2_3 Binary Tree Traversals.pdfUnit 2_3 Binary Tree Traversals.pdf
Unit 2_3 Binary Tree Traversals.pdf
KanchanPatil34
 
Sachin noire 2024
Sachin noire 2024Sachin noire 2024
Sachin noire 2024
sachin kumar
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
SurajSharma266169
 
Data pre processing
Data pre processingData pre processing
Data pre processing
kalavathisugan
 
Tree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BTTree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BT
VikasNirgude2
 
INTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptxINTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptx
AmitSingh770691
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
varagilavanya
 
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATABig Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
Matt Stubbs
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
AryaMNair6
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure Introduction
Abirami A
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
Dr.Umadevi V
 
Data mining 5 klasifikasi decision tree dan random forest
Data mining 5   klasifikasi decision tree dan random forestData mining 5   klasifikasi decision tree dan random forest
Data mining 5 klasifikasi decision tree dan random forest
IrwansyahSaputra1
 
Reviewing basic concepts of relational database
Reviewing basic concepts of relational databaseReviewing basic concepts of relational database
Reviewing basic concepts of relational database
Hitesh Mohapatra
 

Similar to Unit 2_2 Binary Tree as ADT_General Tree.pdf (20)

Data Structures and Algorithm - Week 4 - Trees, Binary Trees
Data Structures and Algorithm - Week 4 - Trees, Binary TreesData Structures and Algorithm - Week 4 - Trees, Binary Trees
Data Structures and Algorithm - Week 4 - Trees, Binary Trees
 
Advanced c c++
Advanced c c++Advanced c c++
Advanced c c++
 
SIX WEEKS SUMMER TRAINING REPORT.pptx
SIX WEEKS SUMMER TRAINING REPORT.pptxSIX WEEKS SUMMER TRAINING REPORT.pptx
SIX WEEKS SUMMER TRAINING REPORT.pptx
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Data model
Data modelData model
Data model
 
Unit 2_3 Binary Tree Traversals.pdf
Unit 2_3 Binary Tree Traversals.pdfUnit 2_3 Binary Tree Traversals.pdf
Unit 2_3 Binary Tree Traversals.pdf
 
Sachin noire 2024
Sachin noire 2024Sachin noire 2024
Sachin noire 2024
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Data pre processing
Data pre processingData pre processing
Data pre processing
 
Tree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BTTree-introduction ,Definition, Types of BT
Tree-introduction ,Definition, Types of BT
 
INTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptxINTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptx
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
 
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATABig Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
Big Data LDN 2018: TIPS AND TRICKS TO WRANGLE BIG, DIRTY DATA
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptx
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure Introduction
 
Database design for HPC
Database design for HPCDatabase design for HPC
Database design for HPC
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Data mining 5 klasifikasi decision tree dan random forest
Data mining 5   klasifikasi decision tree dan random forestData mining 5   klasifikasi decision tree dan random forest
Data mining 5 klasifikasi decision tree dan random forest
 
Reviewing basic concepts of relational database
Reviewing basic concepts of relational databaseReviewing basic concepts of relational database
Reviewing basic concepts of relational database
 

More from KanchanPatil34

Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
KanchanPatil34
 
PAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 MicroporcessorPAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 Microporcessor
KanchanPatil34
 
PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386
KanchanPatil34
 
PAI Unit 2 Segmentation in 80386 microprocessor
PAI Unit 2 Segmentation in 80386 microprocessorPAI Unit 2 Segmentation in 80386 microprocessor
PAI Unit 2 Segmentation in 80386 microprocessor
KanchanPatil34
 
PAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentationPAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentation
KanchanPatil34
 
SE PAI Unit 2_Data Structures in 80386 segmentation
SE PAI Unit 2_Data Structures in 80386 segmentationSE PAI Unit 2_Data Structures in 80386 segmentation
SE PAI Unit 2_Data Structures in 80386 segmentation
KanchanPatil34
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
KanchanPatil34
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
KanchanPatil34
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
KanchanPatil34
 
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
KanchanPatil34
 
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
KanchanPatil34
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
KanchanPatil34
 
Unit 5_Interrupt programming in 8051 micro controller - part 2
Unit 5_Interrupt programming in 8051 micro controller - part 2Unit 5_Interrupt programming in 8051 micro controller - part 2
Unit 5_Interrupt programming in 8051 micro controller - part 2
KanchanPatil34
 
Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1
KanchanPatil34
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
KanchanPatil34
 
Unit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idtUnit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idt
KanchanPatil34
 
Unit 2 se pai_registers in 80386
Unit 2 se pai_registers in 80386Unit 2 se pai_registers in 80386
Unit 2 se pai_registers in 80386
KanchanPatil34
 
Unit i se pai_dos function calls
Unit i se pai_dos function callsUnit i se pai_dos function calls
Unit i se pai_dos function calls
KanchanPatil34
 
DELD Unit V cpld_fpga
DELD Unit V cpld_fpgaDELD Unit V cpld_fpga
DELD Unit V cpld_fpga
KanchanPatil34
 
DELD Unit IV ring and twisted ring counter
DELD Unit IV ring and twisted ring counterDELD Unit IV ring and twisted ring counter
DELD Unit IV ring and twisted ring counter
KanchanPatil34
 

More from KanchanPatil34 (20)

Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
 
PAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 MicroporcessorPAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 Microporcessor
 
PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386
 
PAI Unit 2 Segmentation in 80386 microprocessor
PAI Unit 2 Segmentation in 80386 microprocessorPAI Unit 2 Segmentation in 80386 microprocessor
PAI Unit 2 Segmentation in 80386 microprocessor
 
PAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentationPAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentation
 
SE PAI Unit 2_Data Structures in 80386 segmentation
SE PAI Unit 2_Data Structures in 80386 segmentationSE PAI Unit 2_Data Structures in 80386 segmentation
SE PAI Unit 2_Data Structures in 80386 segmentation
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 1
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
 
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
 
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
 
Unit 5_Interrupt programming in 8051 micro controller - part 2
Unit 5_Interrupt programming in 8051 micro controller - part 2Unit 5_Interrupt programming in 8051 micro controller - part 2
Unit 5_Interrupt programming in 8051 micro controller - part 2
 
Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
Unit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idtUnit 3 se pai_ivt and idt
Unit 3 se pai_ivt and idt
 
Unit 2 se pai_registers in 80386
Unit 2 se pai_registers in 80386Unit 2 se pai_registers in 80386
Unit 2 se pai_registers in 80386
 
Unit i se pai_dos function calls
Unit i se pai_dos function callsUnit i se pai_dos function calls
Unit i se pai_dos function calls
 
DELD Unit V cpld_fpga
DELD Unit V cpld_fpgaDELD Unit V cpld_fpga
DELD Unit V cpld_fpga
 
DELD Unit IV ring and twisted ring counter
DELD Unit IV ring and twisted ring counterDELD Unit IV ring and twisted ring counter
DELD Unit IV ring and twisted ring counter
 

Recently uploaded

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Unit 2_2 Binary Tree as ADT_General Tree.pdf

  • 1. Data Structures Sanjivani Rural Education Society’s Sanjivani College of Engineering, Kopargaon-423603 (An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified Department of Information Technology (NBAAccredited) Ms. K. D. Patil Assistant Professor
  • 2. Tree • General Trees, Tree Terminology, Binary Trees, Use binary trees, Conversion of general tree to binary tree, Array Based representation of Binary Tree, Binary tree as an ADT, Binary tree traversals - recursive and non-recursive algorithms, Construction of tree from its traversals, Huffman coding algorithm Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 3. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Let’s consider a Binary tree of 7 nodes
  • 4. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • For the array representation of binary tree, we have to give numbering to the corresponding nodes. • Start from the root node and move from left to right at every level.
  • 5. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • we have numbered from zero you can simply place the corresponding number in the matching index of an array.
  • 6. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Now Let’s consider a Binary tree
  • 7. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Make the child node of the leaf nodes as NULL
  • 8. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Now number the nodes as done above for the array representation of binary tree.
  • 9. Array Based Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • we have numbered from zero you can simply place the corresponding number in the matching index of an array.
  • 10. Linked List Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • We use a double linked list to represent a binary tree. In a double linked list, every node consists of three fields. • First field for storing left child address, second for storing actual data and third for storing right child address.
  • 11. Linked List Representation of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 12. Binary Tree as an ADT • Binary Tree have a maximum of two children • we can assign direct pointers to them • The declaration of tree nodes is same as in structure to that for doubly linked lists, in that a node is a structure including the key information plus two pointers (left and right) to other nodes • Binary Tree node declaration class Node { int value; Node left; Node right; Node(int value) { this.value = value; right = null; left = null; } }
  • 13. Binary Tree as an ADT Data Structures Mrs. Kanchan Patil Department of Information Technology • Binary Tree class declaration class binary_tree { node left, right; public: btree() { root=NULL; } Isempty(); void create(); void display(); void insert(node,node); void inorder(node); void longestPath(); int depth(node); void display_leaves(node temp); node copy(node first); void copytree(); };
  • 14. General Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • A General Tree is a tree in which each node can have an unlimited out-degree • Each node may have as many children as is necessary to satisfy its requirements • It is also referred as N-array tree • Examples:
  • 15. Changing General Tree to Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • A General Tree we can use following two relations • Parent to Child • Sibling to Sibling • Rules are as follows: • The root of the Binary Tree is the Root of the Generic Tree • The left child of a node in the Generic Tree is the Left child of that node in the Binary Tree • The right sibling of any node in the Generic Tree is the Right child of that node in the Binary Tree
  • 16. Changing General Tree to Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Steps to Convert General Tree to Binary Tree • Step I: • Identify the branch from parent to its first and leftmost child • Step II: • Connect siblings starting with leftmost child using a branch for each siblings to its right siblings. • Step III: • Remove all unneeded branches from the parent to its children. You will get the final binary tree
  • 17. Example Data Structures Mrs. Kanchan Patil Department of Information Technology • Step I: • Identify the branch from parent to its first and leftmost child • Step II: • Connect siblings starting with leftmost child using a branch for each siblings to its right siblings. • Step III: • Remove all unneeded branches from the parent to its children. You will get the final binary tree
  • 18. Example Data Structures Mrs. Kanchan Patil Department of Information Technology • Final Binary Tree:
  • 19. Quiz.. Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 20. Quiz.. Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 21. Inserting into General Trees Data Structures Mrs. Kanchan Patil Department of Information Technology • To insert a node into a general tree, the user must supply the parent of the node. • The new node can be inserted using 3 different ways: • FIFO insertion • LIFO insertion • Key sequenced insertion
  • 22. Inserting into General Trees Data Structures Mrs. Kanchan Patil Department of Information Technology • FIFO insertion: • Insert a node at the end of the sibling list as we insert a node at the rear of a queue
  • 23. Inserting into General Trees Data Structures Mrs. Kanchan Patil Department of Information Technology • LIFO insertion: • Insert a node at the beginning of the sibling list
  • 24. Inserting into General Trees Data Structures Mrs. Kanchan Patil Department of Information Technology • Key sequenced insertion: • Places the new node in key sequence among the sibling nodes • It is most common insertion rule in general trees • It is similar to the insertion rule in a general ordered linked list
  • 25. References Data Structures Mrs. Kanchan Patil Department of Information Technology • R. Lafore, “Data structures and Algorithms in Java”, Pearson education, ISBN: 9788 131718124. • Michael Goodrich, Roberto Tamassia, Michael H. Goldwasser, “Data Structures and Algorithms in Java”, 6th edition, wiley publication, ISBN: 978-1-118-77133-4 • R. Gilberg, B. Forouzan, “Data Structure: A Pseudo code approach with C++”, Cengage Learning. • Sartaj Sahni, “Data Structures, Algorithms and Applications in C++”, 2 nd Edition, Universities Press. • E. Horowitz, S. Sahni, S. Anderson-freed, “Fundamentals of Data Structures in C”, 2 nd Edition, University Press, ISBN 978-81-7371-605-8.
  • 26. Data Structures Mrs. Kanchan Patil Department of Information Technology Thank You!!! Happy Learning!!!