SlideShare a Scribd company logo
1 of 39
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
Tree
• Linear Vs. Non-linear Data Structure
• Introduction to Tree
• Basic Tree Terminologies
• Example
Data Structures Mrs. Kanchan Patil Department of Information Technology
Learning Outcomes
• At the end of this lecture, student will able to-
• Differentiate linear and Non-linear Data Structures
• Introduce Tree data structure
• Explain different terms related to Tree data structure
Data Structures Mrs. Kanchan Patil Department of Information Technology
Recap!!!
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Data Structures: It is a particular way of organizing data in a computer.
Reference https://www.geeksforgeeks.org/difference-between-linear-and-non-linear-data-structures/
Linear Vs. Non-Linear Data Structures
Data Structures Mrs. Kanchan Patil Department of Information Technology
Sr. No. Linear Data Structure Non-Linear Data Structure
1 Data elements are arranged in a linear order. Elements
are attached to its previous and next adjacent.
Data elements are attached in hierarchically manner.
2 Single level is involved. Multiple levels are involved.
3 Its implementation is easy in comparison to non-linear
data structure.
Its implementation is complex in comparison to linear
data structure.
4 Data elements can be traversed in a single run only. Data elements can’t be traversed in a single run only.
5 Memory is not utilized in an efficient way. Memory is utilized in an efficient way.
6 Examples: array, stack, queue, linked list, etc. Examples: trees and graphs.
7 Applications:
Stack: undo, redo functions in editor
Queue: CPU job scheduling
Arrays: Storage of matrices
Linked List: Polynomial implementation for
mathematical operations
Applications: In Artificial Intelligence and image
processing.
Tree: 1. Implementing the hierarchical structures in
computer systems like directory and file system.
2. Implementing the navigation structure of a website.
Graph: Routes in GPS
Introduction to Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Non-linear data structure
• It has a structure that forms a parent-child relationship
• Collection of nodes and edges, the edges could be directed or undirected
• Definition (recursively):
• A tree is a finite set of one or more nodes such that
• There is a specially designated node called root.
• The remaining nodes are partitioned into n>=0 disjoint set T1,…,Tn, where
each of these sets is a tree. T1,…,Tn are called the subtrees of the root.
• Every node in the tree is the root of some subtree
Example
Data Structures Mrs. Kanchan Patil Department of Information Technology
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Node: It is a separate data structure that contains data or
value for a tree.
• Root: It is the top node in a tree. In any tree, first node is root
node.
• Parent: A node that has sub trees is the parent of the roots of
the sub-trees. The node which is a predecessor of any node is
called as Parent Node. The node which has a branch from it
to any other node is called a parent node. Parent node can
also be defined as "The node which has child / children".
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Children: A node connected to the previous node is known as
the child node. Each node in the tree is the child node of the
root node. The node which is descendant of any node is called
as Child Node. The node which has a link from its parent node is
called as child node. In a tree, any parent node can have any
number of child nodes.
• Siblings: Children of the same parent are siblings. The nodes
with the same parent are called Sibling nodes.
• Size: The total number of nodes present in the tree.
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Ancestors: All the nodes along the path from the root to the
node.
• Edge: The connecting link between any two nodes is called
as Edge. In a tree with 'N' number of nodes there will be a
maximum of 'N-1' number of edges.
• Terminal nodes (or leaf): The node which does not have a
child is called as leaf Node. Leaf has degree 0. A leaf is a
node with no child. The leaf nodes are also called
as External Nodes/Terminal Nodes.
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Non-terminal nodes: An internal node is a node with atleast
one child. Nodes other than leaf nodes are called as Internal
Nodes/ Non-terminal nodes. The root node is also said to be
Internal Node if the tree has more than one node.
• Degree of a node: The degree of a node is the number of sub
trees of the node. The total number of children of a node is
called as Degree of that Node.
• Degree of a tree: The highest degree of a node among all the
nodes in a tree is called as 'Degree of Tree'
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Level of Node: If a node is at level l, then it children are at level l+1. if, the root
node is said to be at Level 0 then children of root node are at Level 1 and the
children of the nodes which are at Level 1 will be at Level 2 and so on. Each step
from top to bottom is called as a Level and the Level count starts with '0' and
incremented by one at each level.
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Depth/ Height:
• The height of tree is the level of the leaf in the longest path from the root plus 1
• So, By definition,
• Height of empty tree is -1
• Example:
• Height of given tree = 3+1 =4
Basic Tree Terminologies
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Path: The sequence of Nodes and Edges from one
node to another node is called as path between that
two Nodes. Length of a Path is total number of nodes
in that path. In given example, the path A - B - E - J has
length 4.
• Sub-tree: A tree T is a tree consisting of a node
in T and all of its descendants in T. Each child from a
node forms a subtree recursively. Every child node will
form a subtree on its parent node.
Quiz…
Data Structures Mrs. Kanchan Patil Department of Information Technology
Quiz…
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Root Node: A
• Parent of D and E: B
• sibling of B: C
• children of B: D and E
• External nodes : D, E, F, G, I
• Internal Nodes : A, B, C, H
• The level of E: 2
• The height (depth) of the tree: 4
• The degree of node B: 2
• The degree of the tree: 3
• The ancestors of node I: A, C, H
• The descendants of node C: F, G, H, I
Tree Representation
Data Structures Mrs. Kanchan Patil Department of Information Technology
• A tree is generally implemented in computer using “pointers/links”
• But, outside the computer systems, it can be represented using
• Organization chart format
• Indented list
• Parenthetical listing
Tree Representation
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Organization chart format
• Notations we use to represent tree is called
general tree
• Not easily implemented in computer systems
database
• Large structure may get complex
• Example:
• Computer parts list as a general tree
Computer
CPU
Controller ALU
Hardware
devices
Pen-Drive CD-ROM
Tree Representation
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Indented list
• Represents the assembly structure of an item
• Overcomes the disadvantage of chart format
• Sometimes, called as “goezinto” means “goes
into”
• Example:
• Computer parts list as a indented list
3. Computer
3.1 CPU
3.1.1 Controller
3.1.2 ALU
3.2 Hardware Devices
3.2.1 CD-ROM
3.2.2 Pen-Drive
Tree Representation
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Parenthetical listing
• It is used in algebraic expressions
• When a tree is represented in
parenthetical notations, each open
parenthesis indicates the start of new
level
• Each closing parenthesis completes
the current level and moves up one
level in the tree
• Example
• Parenthetical notation for below
tree is: A(B(D(HI)E(J))C(FG(K)))
Introduction to Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• A tree in which every node can have a maximum of two children is called as Binary
Tree
• It is a tree in which no node can have more than two sub-trees
• Every node can have either 0 children or 1 child or 2 children but not more than 2
children
• The sub-trees are designated as left sub-tree (left child) and the other one is right
sub-tree (right child). One or both can be NULL
• Each sub-tree is itself binary tree
• A null tree is a tree with no nodes
• Symmetry is not a tree requirement
Example
Data Structures Mrs. Kanchan Patil Department of Information Technology
A
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Height of Binary Tree:
• Considering number of nodes of binary tree as N,
• Maximum height Hmax is given as,
Hmax = N
• The tree with maximum height is rare, it occurs when
the entire tree is build in one direction
• Minimum height, Hmin is calculated as,
Hmin = [log2N] + 1
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Height of Binary Tree:
• Given a height of tree H,
• Minimum number of nodes in tree, Nmin = H
(in case of left skewed and right skewed binary tree)
• Maximum number of nodes in tree, Nmax = 𝟐𝑯 - 1
(in case of full binary tree)
• Example: Height of left hand side tree is 3, so minimum
number of nodes in tree = 3
• Height of right hand side tree is 3, so maximum number of
nodes in tree = 23-1 = 7
Quiz..
Data Structures Mrs. Kanchan Patil Department of Information Technology
• What will be the maximum and the minimum number of nodes in a binary tree of
height 5 are?
• Which of the following height is not possible for a binary tree with 50 nodes?
(A) 4 (B) 5 (C) 6 (D) None
Solution: Minimum height with 50 nodes = floor(log50) = 5. Therefore, height 4 is not
possible.
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Complete/Nearly Complete Binary Tree:
• A binary tree T is said to be complete binary tree if it has
maximum number of nodes for its height
• The maximum entry is reached when the last level is full
• A tree is considered nearly complete if it has minimum
height for it’s nodes and all the nodes in the last level are
found on left
• All the levels are completely filled except possibly the last
level and the last level has all keys as left as possible
Nearly Complete Binary Tree
Complete Binary Tree
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Full Binary Tree:
• A Binary Tree is a full binary tree if every node has 0 or 2 children
• It is a binary tree in which all nodes except leaf nodes have two
children
• Perfect Binary Tree:
• A Binary tree is a Perfect Binary Tree in which all the internal
nodes have two children and all leaf nodes are at the same level.
• It has 2i nodes at level i
• No. of leaf nodes = No. of internal nodes + 1
• Total no. of nodes = (2 * i) +1 where, i is internal node
Full Binary Tree
Perfect Binary Tree
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
Quiz..
Data Structures Mrs. Kanchan Patil Department of Information Technology
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Balance Factor:
• The distance of a node from the root determines how efficiently it can be located
• The children of any node in a tree can be accessed by following only one path, the one
that needs to the desired node
• Shorter the tree, it is easier to locate any node in the tree
• To determine weather the tree is balanced, balance factor can be calculated
• Balance factor of a tree is the difference in height between its left and right sub-trees
• Balance factor, B can be determined by the formula,
B = HL – HR,
where, HL = Height of left subtree and HR is height of right subtree
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Balance Factor:
• The tree is said to be balanced, if its balance factor is 0 and its sub-trees are also
balanced.
• As, A binary tree is balanced if the height of its sub-trees differs by no more than one
(it can be -1, 0, +1) and its sub-trees are also balanced
A
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Example:
Quiz..
Data Structures Mrs. Kanchan Patil Department of Information Technology
Properties of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Binary Tree Structure:
• Each node contains data and two pointers, one to point left sub-tree and another to
point right sub-tree
Node
• left subtree <pointer to node>
• data <data type>
• right subtree <pointer to node>
End node
Advantages of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Searching in Binary tree become faster
• Binary tree provides six traversals
• Two of six traversals give sorted order of elements
• Maximum and minimum elements can be directly picked up
• It is used for graph traversal and to convert an expression to postfix and prefix forms
Applications of Binary Tree
Data Structures Mrs. Kanchan Patil Department of Information Technology
• Search Engines: Organize and index web pages
• File System: Organize and index files
• Searching and Sorting: Binary Search, quicksort, merge sort
• Expression Tree: To represent mathematical expressions
• Huffman Coding: data compression
• Decision Tree: Machine Learning and Data Mining model
• Game AI: to model different possibilities and outcome of game
• TRIE: Storage and string retrieval
• Cryptography: generate and manage encryption, decryption keys
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.
• https://www.geeksforgeeks.org/difference-between-linear-and-non-linear-data-
structures/
• http://www.btechsmartclass.com/data_structures/tree-terminology.html
Data Structures Mrs. Kanchan Patil Department of Information Technology
Thank You!!!
Happy Learning!!!

More Related Content

Similar to Data Structures Tree Guide

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 TreesFerdin Joe John Joseph PhD
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptxRahulAI
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfKanchanPatil34
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structuresASairamSairam1
 
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
 
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.ppt
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.pptweek1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.ppt
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.pptRidoVercascade
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsBHARATH KUMAR
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediateMD. MARUFUZZAMAN .
 

Similar to Data Structures Tree Guide (20)

DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
104333 sri vidhya eng notes
104333 sri vidhya eng notes104333 sri vidhya eng notes
104333 sri vidhya eng notes
 
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
 
Tree Introduction.pptx
Tree Introduction.pptxTree Introduction.pptx
Tree Introduction.pptx
 
Database design for HPC
Database design for HPCDatabase design for HPC
Database design for HPC
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Unit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdfUnit 1_SLL and DLL.pdf
Unit 1_SLL and DLL.pdf
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 
Tree 11.ppt
Tree 11.pptTree 11.ppt
Tree 11.ppt
 
B+ trees and height balance tree
B+ trees and height balance treeB+ trees and height balance tree
B+ trees and height balance tree
 
Trees
TreesTrees
Trees
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
Unit II,III - Data Structures.pdf
Unit II,III - Data Structures.pdfUnit II,III - Data Structures.pdf
Unit II,III - Data Structures.pdf
 
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
 
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.ppt
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.pptweek1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.ppt
week1-thursday-2id50-q2-2021-2022-intro-and-basic-fd.ppt
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
 

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

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
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
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
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
 
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 🔝✔️✔️
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Data Structures Tree Guide

  • 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. Tree • Linear Vs. Non-linear Data Structure • Introduction to Tree • Basic Tree Terminologies • Example Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 4. Learning Outcomes • At the end of this lecture, student will able to- • Differentiate linear and Non-linear Data Structures • Introduce Tree data structure • Explain different terms related to Tree data structure Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 5. Recap!!! Data Structures Mrs. Kanchan Patil Department of Information Technology • Data Structures: It is a particular way of organizing data in a computer. Reference https://www.geeksforgeeks.org/difference-between-linear-and-non-linear-data-structures/
  • 6. Linear Vs. Non-Linear Data Structures Data Structures Mrs. Kanchan Patil Department of Information Technology Sr. No. Linear Data Structure Non-Linear Data Structure 1 Data elements are arranged in a linear order. Elements are attached to its previous and next adjacent. Data elements are attached in hierarchically manner. 2 Single level is involved. Multiple levels are involved. 3 Its implementation is easy in comparison to non-linear data structure. Its implementation is complex in comparison to linear data structure. 4 Data elements can be traversed in a single run only. Data elements can’t be traversed in a single run only. 5 Memory is not utilized in an efficient way. Memory is utilized in an efficient way. 6 Examples: array, stack, queue, linked list, etc. Examples: trees and graphs. 7 Applications: Stack: undo, redo functions in editor Queue: CPU job scheduling Arrays: Storage of matrices Linked List: Polynomial implementation for mathematical operations Applications: In Artificial Intelligence and image processing. Tree: 1. Implementing the hierarchical structures in computer systems like directory and file system. 2. Implementing the navigation structure of a website. Graph: Routes in GPS
  • 7. Introduction to Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Non-linear data structure • It has a structure that forms a parent-child relationship • Collection of nodes and edges, the edges could be directed or undirected • Definition (recursively): • A tree is a finite set of one or more nodes such that • There is a specially designated node called root. • The remaining nodes are partitioned into n>=0 disjoint set T1,…,Tn, where each of these sets is a tree. T1,…,Tn are called the subtrees of the root. • Every node in the tree is the root of some subtree
  • 8. Example Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 9. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Node: It is a separate data structure that contains data or value for a tree. • Root: It is the top node in a tree. In any tree, first node is root node. • Parent: A node that has sub trees is the parent of the roots of the sub-trees. The node which is a predecessor of any node is called as Parent Node. The node which has a branch from it to any other node is called a parent node. Parent node can also be defined as "The node which has child / children".
  • 10. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Children: A node connected to the previous node is known as the child node. Each node in the tree is the child node of the root node. The node which is descendant of any node is called as Child Node. The node which has a link from its parent node is called as child node. In a tree, any parent node can have any number of child nodes. • Siblings: Children of the same parent are siblings. The nodes with the same parent are called Sibling nodes. • Size: The total number of nodes present in the tree.
  • 11. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Ancestors: All the nodes along the path from the root to the node. • Edge: The connecting link between any two nodes is called as Edge. In a tree with 'N' number of nodes there will be a maximum of 'N-1' number of edges. • Terminal nodes (or leaf): The node which does not have a child is called as leaf Node. Leaf has degree 0. A leaf is a node with no child. The leaf nodes are also called as External Nodes/Terminal Nodes.
  • 12. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Non-terminal nodes: An internal node is a node with atleast one child. Nodes other than leaf nodes are called as Internal Nodes/ Non-terminal nodes. The root node is also said to be Internal Node if the tree has more than one node. • Degree of a node: The degree of a node is the number of sub trees of the node. The total number of children of a node is called as Degree of that Node. • Degree of a tree: The highest degree of a node among all the nodes in a tree is called as 'Degree of Tree'
  • 13. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Level of Node: If a node is at level l, then it children are at level l+1. if, the root node is said to be at Level 0 then children of root node are at Level 1 and the children of the nodes which are at Level 1 will be at Level 2 and so on. Each step from top to bottom is called as a Level and the Level count starts with '0' and incremented by one at each level.
  • 14. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Depth/ Height: • The height of tree is the level of the leaf in the longest path from the root plus 1 • So, By definition, • Height of empty tree is -1 • Example: • Height of given tree = 3+1 =4
  • 15. Basic Tree Terminologies Data Structures Mrs. Kanchan Patil Department of Information Technology • Path: The sequence of Nodes and Edges from one node to another node is called as path between that two Nodes. Length of a Path is total number of nodes in that path. In given example, the path A - B - E - J has length 4. • Sub-tree: A tree T is a tree consisting of a node in T and all of its descendants in T. Each child from a node forms a subtree recursively. Every child node will form a subtree on its parent node.
  • 16. Quiz… Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 17. Quiz… Data Structures Mrs. Kanchan Patil Department of Information Technology • Root Node: A • Parent of D and E: B • sibling of B: C • children of B: D and E • External nodes : D, E, F, G, I • Internal Nodes : A, B, C, H • The level of E: 2 • The height (depth) of the tree: 4 • The degree of node B: 2 • The degree of the tree: 3 • The ancestors of node I: A, C, H • The descendants of node C: F, G, H, I
  • 18. Tree Representation Data Structures Mrs. Kanchan Patil Department of Information Technology • A tree is generally implemented in computer using “pointers/links” • But, outside the computer systems, it can be represented using • Organization chart format • Indented list • Parenthetical listing
  • 19. Tree Representation Data Structures Mrs. Kanchan Patil Department of Information Technology • Organization chart format • Notations we use to represent tree is called general tree • Not easily implemented in computer systems database • Large structure may get complex • Example: • Computer parts list as a general tree Computer CPU Controller ALU Hardware devices Pen-Drive CD-ROM
  • 20. Tree Representation Data Structures Mrs. Kanchan Patil Department of Information Technology • Indented list • Represents the assembly structure of an item • Overcomes the disadvantage of chart format • Sometimes, called as “goezinto” means “goes into” • Example: • Computer parts list as a indented list 3. Computer 3.1 CPU 3.1.1 Controller 3.1.2 ALU 3.2 Hardware Devices 3.2.1 CD-ROM 3.2.2 Pen-Drive
  • 21. Tree Representation Data Structures Mrs. Kanchan Patil Department of Information Technology • Parenthetical listing • It is used in algebraic expressions • When a tree is represented in parenthetical notations, each open parenthesis indicates the start of new level • Each closing parenthesis completes the current level and moves up one level in the tree • Example • Parenthetical notation for below tree is: A(B(D(HI)E(J))C(FG(K)))
  • 22. Introduction to Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • A tree in which every node can have a maximum of two children is called as Binary Tree • It is a tree in which no node can have more than two sub-trees • Every node can have either 0 children or 1 child or 2 children but not more than 2 children • The sub-trees are designated as left sub-tree (left child) and the other one is right sub-tree (right child). One or both can be NULL • Each sub-tree is itself binary tree • A null tree is a tree with no nodes • Symmetry is not a tree requirement
  • 23. Example Data Structures Mrs. Kanchan Patil Department of Information Technology A
  • 24. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Height of Binary Tree: • Considering number of nodes of binary tree as N, • Maximum height Hmax is given as, Hmax = N • The tree with maximum height is rare, it occurs when the entire tree is build in one direction • Minimum height, Hmin is calculated as, Hmin = [log2N] + 1
  • 25. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Height of Binary Tree: • Given a height of tree H, • Minimum number of nodes in tree, Nmin = H (in case of left skewed and right skewed binary tree) • Maximum number of nodes in tree, Nmax = 𝟐𝑯 - 1 (in case of full binary tree) • Example: Height of left hand side tree is 3, so minimum number of nodes in tree = 3 • Height of right hand side tree is 3, so maximum number of nodes in tree = 23-1 = 7
  • 26. Quiz.. Data Structures Mrs. Kanchan Patil Department of Information Technology • What will be the maximum and the minimum number of nodes in a binary tree of height 5 are? • Which of the following height is not possible for a binary tree with 50 nodes? (A) 4 (B) 5 (C) 6 (D) None Solution: Minimum height with 50 nodes = floor(log50) = 5. Therefore, height 4 is not possible.
  • 27. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Complete/Nearly Complete Binary Tree: • A binary tree T is said to be complete binary tree if it has maximum number of nodes for its height • The maximum entry is reached when the last level is full • A tree is considered nearly complete if it has minimum height for it’s nodes and all the nodes in the last level are found on left • All the levels are completely filled except possibly the last level and the last level has all keys as left as possible Nearly Complete Binary Tree Complete Binary Tree
  • 28. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Full Binary Tree: • A Binary Tree is a full binary tree if every node has 0 or 2 children • It is a binary tree in which all nodes except leaf nodes have two children • Perfect Binary Tree: • A Binary tree is a Perfect Binary Tree in which all the internal nodes have two children and all leaf nodes are at the same level. • It has 2i nodes at level i • No. of leaf nodes = No. of internal nodes + 1 • Total no. of nodes = (2 * i) +1 where, i is internal node Full Binary Tree Perfect Binary Tree
  • 29. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 30. Quiz.. Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 31. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Balance Factor: • The distance of a node from the root determines how efficiently it can be located • The children of any node in a tree can be accessed by following only one path, the one that needs to the desired node • Shorter the tree, it is easier to locate any node in the tree • To determine weather the tree is balanced, balance factor can be calculated • Balance factor of a tree is the difference in height between its left and right sub-trees • Balance factor, B can be determined by the formula, B = HL – HR, where, HL = Height of left subtree and HR is height of right subtree
  • 32. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Balance Factor: • The tree is said to be balanced, if its balance factor is 0 and its sub-trees are also balanced. • As, A binary tree is balanced if the height of its sub-trees differs by no more than one (it can be -1, 0, +1) and its sub-trees are also balanced A
  • 33. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Example:
  • 34. Quiz.. Data Structures Mrs. Kanchan Patil Department of Information Technology
  • 35. Properties of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Binary Tree Structure: • Each node contains data and two pointers, one to point left sub-tree and another to point right sub-tree Node • left subtree <pointer to node> • data <data type> • right subtree <pointer to node> End node
  • 36. Advantages of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Searching in Binary tree become faster • Binary tree provides six traversals • Two of six traversals give sorted order of elements • Maximum and minimum elements can be directly picked up • It is used for graph traversal and to convert an expression to postfix and prefix forms
  • 37. Applications of Binary Tree Data Structures Mrs. Kanchan Patil Department of Information Technology • Search Engines: Organize and index web pages • File System: Organize and index files • Searching and Sorting: Binary Search, quicksort, merge sort • Expression Tree: To represent mathematical expressions • Huffman Coding: data compression • Decision Tree: Machine Learning and Data Mining model • Game AI: to model different possibilities and outcome of game • TRIE: Storage and string retrieval • Cryptography: generate and manage encryption, decryption keys
  • 38. 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. • https://www.geeksforgeeks.org/difference-between-linear-and-non-linear-data- structures/ • http://www.btechsmartclass.com/data_structures/tree-terminology.html
  • 39. Data Structures Mrs. Kanchan Patil Department of Information Technology Thank You!!! Happy Learning!!!