SlideShare a Scribd company logo
1 of 26
Download to read offline
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

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.pptxsagabo1
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemSelshaCs
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
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.pdfKanchanPatil34
 
INTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptxINTRODUCTION TO DATA STRUCTURE.pptx
INTRODUCTION TO DATA STRUCTURE.pptxAmitSingh770691
 
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 DATAMatt Stubbs
 
DATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxDATA STUCTURES-TREES.pptx
DATA STUCTURES-TREES.pptxAryaMNair6
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionAbirami A
 
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 forestIrwansyahSaputra1
 
Reviewing basic concepts of relational database
Reviewing basic concepts of relational databaseReviewing basic concepts of relational database
Reviewing basic concepts of relational databaseHitesh Mohapatra
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structureMahmoud Alfarra
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)Madishetty Prathibha
 

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

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
 
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
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
 

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.pdfKanchanPatil34
 
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 MicroporcessorKanchanPatil34
 
PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386KanchanPatil34
 
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 microprocessorKanchanPatil34
 
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 segmentationKanchanPatil34
 
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 segmentationKanchanPatil34
 
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 1KanchanPatil34
 
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 2KanchanPatil34
 
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 3KanchanPatil34
 
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 2KanchanPatil34
 
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 1KanchanPatil34
 
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 8051KanchanPatil34
 
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 2KanchanPatil34
 
Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1KanchanPatil34
 
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 idtKanchanPatil34
 
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 80386KanchanPatil34
 
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 callsKanchanPatil34
 
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 counterKanchanPatil34
 

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

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 

Recently uploaded (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

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!!!