SlideShare a Scribd company logo
BY
A. RAJITHA
DL in Computer Science
TTWRDC- SpARK, NAGARAM-
 What is Non Linear Data Structure?
 What is importance of Non Linear Data Structures
 Different Non Linear Data Structures
 Operations of each Non Linear Data Structures
 Applications of each Non Linear Data Structures
 Questioner
 A Non-Linear Data structures is a data structure in which
data item is connected to several other data items.
 Non-Linear data structure may exhibit either a
hierarchical relationship or parent-child relationship.
 In non-linear data structures, every data element may
have more than one predecessor as well as successor.
 Elements do not form any particular linear sequence.
Non-linear data structures are capable of expressing
more complex relationships than linear data structures.
The memory is utilized efficiently in the non-linear data
structure where linear data structure tends to waste the
memory.
One big drawback of linked list is, random access
is not allowed.
 Trees
A tree is a non-empty set one element of which is
designated the root of the tree while the remaining
elements are partitioned into non-empty sets each of which
is a sub-tree of the root.
 Graph
A graph G is a discrete structure consisting of nodes
(vertices) and the lines joining the nodes (edges).
Trees are non linear data structure
that can be represented in a
hierarchical manner.
 A tree contains a finite
non-empty set of elements.
 Any two nodes in the tree are
connected with a relationship
of parent-child.
 Every individual elements in a tree
can have any number of sub trees.
 It represents the nodes
connected by edges
Root : The basic node of all nodes in the tree. All
operations on the tree are performed with passing root
node to the functions.
Child : a successor node connected to a node is called
child. A node in binary tree may have at most two children.
 Parent : a node is said to be parent node to all its child
nodes.
Leaf : a node that has no child nodes.
Siblings : Two nodes are siblings if they are children to
the same parent node.
Ancestor : a node which is parent of parent node ( B is
ancestor node to D,E and F ).
Descendent : a node which is child of child node ( D, E
and F are descendent nodes of node B )
 Level : The distance of a node from the root node, The
root is at level – 0,( B and C at Level 1 and D, E, F have
Level 2 ( highest level of tree is called height of tree )
 Degree : The number of nodes connected to a particular
parent node.
Path : Path is a number of successive edges from source
node to destination node.
Edge : Edge is connection between one node to another node
Path : Path is a number of successive edges from source node
to destination node.
Edge : Edge is connection between one node to another node.
Height of a node : It represents number of edges on the
longest path between that node and a leaf.
Height of a Tree : It represents the height of root node.
Depth of a Tree: Depth of a tree represents the number
edges from the tree’s root node to the node.
 Free tree
Rooted tree
 Ordered tree
 Regular tree
 Binary tree
Complete Binary tree
Binary Search tree
 A free tree is a connected, acyclic graph .
 It is undirected graph
 It has no node designated as a root
 As it is connected, any node can be reached from any
other node by a unique path
Figure: Free Tree
 Unlike free tree, rooted tree is a directed graph in which
one node is designated as root, whose incoming degree is
zero
 And for all other nodes incoming degree is one.
Figure: Rooted Tree
 In many applications the relative order of the nodes at any
particular level assumes some significance
 It is easy to impose an order on the nodes at a level by
referring to a particular node as the first node, to another
node as the second, and so on
 Such ordering can be
done left to right
Ordered Tree
 A tree in which each branch node vertex has the same
out degree is called as Regular Tree.
 If in a directed tree, the out degree of every node is
less than or equal to m, then the tree is called as an
m-ary tree.
 If the out degree of every node is exactly equal to m
(branch nodes) or zero (leaf nodes) then the tree is
called as regular m-ary tree.
In a binary tree, each node can
have at most two children.
A binary tree is either empty or
consists of a node called the root
together with two binary trees
called the left subtree and
the right subtree.
 Node with 2 children are called internal nodes and
nodes with 0 children are called external nodes
 Assigning level numbers and Numbering of nodes
for a binary tree:
The nodes of a binary tree can be numbered in a
natural way
level by level
left to right.
 The nodes of a complete binary tree can be numbered so
that the root is assigned the number 1.
 A left child is assigned twice the number assigned its
parent.
 A right child is assigned one more than twice the number
assigned its parent.
 If h = height of a binary tree, then
a. Maximum number of leaves = 2h
b. Maximum number of nodes = 2h + 1 - 1
 If a binary tree contains m nodes at level l, it contains at
most 2m nodes at level l + 1.
 Since a binary tree can contain at most one node at
level 0 (the root), it can contain at most 2l node at level l
 The total number of edges in a full binary tree with n node
is n - 1.
 If every non-leaf node in a binary
tree has nonempty left and right sub trees, the tree is
termed a strictly binary tree.
 A strictly binary tree with n
leaves always contains 2n – 1
nodes.
 A full binary tree of height h has all its leaves at level h.
 All non leaf nodes of a full binary tree have two children,
and the leaf nodes have no children.
A full binary tree with height h has 2h + 1 - 1 nodes. A full
binary tree of height h is a strictly binary tree all of whose
leaves are at level h.
For example, a full
binary tree of height 3
contains 23+1 – 1 = 15 nodes.
 A binary tree with n nodes is said to be complete if it
contains all the first n nodes of the above numbering
scheme.
A complete binary tree of height h looks like a full binary
tree down to level h-1, and the level h is filled from left to
right.
Leaf nodes at level n
occupy the leftmost
positions in the tree
 A Binary tree is Perfect Binary Tree in which all internal
nodes have two children and all leaves are at same level.
 A Perfect Binary Tree of height h has 2h – 1 non leaf
nodes.
Array Representation
In array representation of a binary tree, we use one-
dimensional array (1-D Array) to represent a binary tree.
This numbering can start from 0 to (n-1) or from 1 to n.
Lets derive the positions of nodes and their parent and child
nodes in the array.
When we use 0 index based sequencing,
Suppose parent node is an index p.
Then, the left child node is at index (2*p)+ 1.
The right child node is at index (2*p) + 2.
Root node is at index 0.
left_child is at index 1.
Right_child is at index 2.
When we use 1 index based sequencing,
Suppose parent node is at index p,
Right node is at index (2*p).
Left node is at index (2*p)+1.
Root node is at index 1.
Left child is at index 2.
Right child is at index 3.
0 1 2 3 4 5 6 7 8 9 10 11………………..20
ADVANTAGES
 Any node can be accesses from any other node by
calculating the index.
 Here, data are stored without any pointers to their successor
or ancestor.
DISADVANTAGES
 Other than full binary trees, majority of the array entries may
be empty
 A new node to it or deleting a node from it are inefficient
with this representation
Linked List Representation
 Binary trees can be represented by links where each node
contains the address of the left child and the right child.
If any node has its left or right child empty then it will have in
its respective link field, a null value.
A leaf node has null value in both of its links.
Node Structure in Binary Tree
ADVANTAGES
 The drawback of sequential representation are overcome
in this representation .
 We may or may not know the tree depth in advance. Also
for unbalanced tree, memory is not wasted.
 Insertion and deletion operations are more efficient in
this representation.
DISADVANTAGES
 In this representation, there is no direct access to any
node .
 It has to be traversed from root to reach to a particular
node
 As compared to sequential representation memory
needed per node is more.
 This is due to two link fields (left child and right child
for binary trees) in node
Creation : Creating an empty binary tree to which ‘root‘ points .
Traversal : To Visiting all the nodes in a binary tree
Deletion : To Deleting a node from a non-empty binary tree
Insertion : To Inserting a node into an existing/empty binary tree.
Merge : To Merging two binary trees
Copy : Copying a binary tree .
Compare : Comparing two binary trees.
Find replica or mirror
 A binary tree is defined recursively: it consists
of a root, a left sub tree, and a right sub tree.
 To traverse (or walk) the binary tree is to visit each
node in the binary tree exactly once.
 Tree traversals are naturally recursive.
 Standard traversal orderings:
• preorder
• inorder
• postorder
In Preorder, the root
is visited before (pre)
the subtrees traversals.
 In Inorder, the root is
visited in-between left
and right subtree traversal.
 In Postorder, the root
is visited after (post)
the subtrees traversals
Assume: visiting a node
is printing its data
• Preorder: 15 8 2 6 3 7 11 10
12 14 20 27 22 30
• Inorder: 2 3 6 7 8 10 11 12
14 15 20 22 27 30
• Postorder: 3 7 6 2 10 14 12 11
8 22 30 27 20 15
 Stores keys in the nodes in a way so that searching,
insertion and deletion can be done efficiently.
Binary Search Tree Property
For every node X, all the keys in
its left subtree are smaller than
the key value in X, and all the
keys in its right subtree
are larger than the key value in X
Binary Tree Non Binary Tree
 If we are searching for 15,
then we are done.
If we are searching for a
key < 15, then we should
search in the left subtree.
If we are searching for a
key > 15, then we should
search in the right subtree.
 FindMinimum: Start at the root and go left as
long as there is a left child. The stopping point is
the smallest element
FindMaxmum: Start at the root and go right as
long as there is a right child. The stopping point is
the largest element
Ascending order: Inorder traversal of a binary
search tree gives prints elements in sorted order.
 Storing naturally hierarchical data
• File System
• Organizational Structure of an institution
• Class inheritance tree
 Organize data for quick search, insertion, deletion-
Binary Search Tree.
 Dictionary
 Networking Routing Algorithm.
Problem representation
• Expression trees
• Decision tree.
1. Construct the tree from the following preorder and inorder
travels: Preorder: a,b,c,d,e,g,h,j,f. Inorder: c,d,b,a,h,g,j,e,f.
Construct a binary search tree with the below information.
The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12.
Preorder Traversal is 10, 4, 3, 5, 11, 12. Inorder Traversal of Binary
search tree is equal to ascending order of the nodes of the Tree.
Inorder Traversal is 3, 4, 5, 10, 11, 12.
The tree constructed using
Preorder and Inorder
traversal is
NON-LINEAR DATA STRUCTURE-TREES.pptx

More Related Content

What's hot

Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
Saurabh Mishra
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
Äshïsh Jäïn
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
Vrushali Dhanokar
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
Adarsh Patel
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
Soumen Santra
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
Madhu Bala
 
Trees
TreesTrees
Trees data structure
Trees data structureTrees data structure
Trees data structure
Sumit Gupta
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
chauhankapil
 
Expression trees
Expression treesExpression trees
Expression trees
Salman Vadsarya
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structureghhgj jhgh
 

What's hot (20)

Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Graph representation
Graph representationGraph representation
Graph representation
 
single linked list
single linked listsingle linked list
single linked list
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Trees
TreesTrees
Trees
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
Expression trees
Expression treesExpression trees
Expression trees
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 

Similar to NON-LINEAR DATA STRUCTURE-TREES.pptx

Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
Guru Nanak Institute Of Tech
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 
Trees
TreesTrees
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
SIVAKUMARM603675
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
nakulvarshney371
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
worldchannel
 
AD3251-Data Structures Design-Notes-Tree.pdf
AD3251-Data Structures  Design-Notes-Tree.pdfAD3251-Data Structures  Design-Notes-Tree.pdf
AD3251-Data Structures Design-Notes-Tree.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
ASairamSairam1
 
Binary tree
Binary  treeBinary  tree
Binary tree
Vanitha Chandru
 
Tree
TreeTree
Tree
bhumish
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
smruti sarangi
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
SurajSharma266169
 
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
sumitbardhan
 
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
BHARATH KUMAR
 
Data structure tree - intermediate
Data structure tree - intermediateData structure tree - intermediate
Data structure tree - intermediate
MD. MARUFUZZAMAN .
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
Dabbal Singh Mahara
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
DhanushSrinivasulu
 
Tree
TreeTree

Similar to NON-LINEAR DATA STRUCTURE-TREES.pptx (20)

Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Trees
TreesTrees
Trees
 
UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
Final tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentationFinal tree.ppt tells about tree presentation
Final tree.ppt tells about tree presentation
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
AD3251-Data Structures Design-Notes-Tree.pdf
AD3251-Data Structures  Design-Notes-Tree.pdfAD3251-Data Structures  Design-Notes-Tree.pdf
AD3251-Data Structures Design-Notes-Tree.pdf
 
Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
Trees in data structures
Trees in data structuresTrees in data structures
Trees in data structures
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Tree
TreeTree
Tree
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
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
 
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
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Tree
TreeTree
Tree
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
"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
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
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
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
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
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
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
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
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
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
"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...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
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
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
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 Á...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
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 ...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

NON-LINEAR DATA STRUCTURE-TREES.pptx

  • 1. BY A. RAJITHA DL in Computer Science TTWRDC- SpARK, NAGARAM-
  • 2.  What is Non Linear Data Structure?  What is importance of Non Linear Data Structures  Different Non Linear Data Structures  Operations of each Non Linear Data Structures  Applications of each Non Linear Data Structures  Questioner
  • 3.  A Non-Linear Data structures is a data structure in which data item is connected to several other data items.  Non-Linear data structure may exhibit either a hierarchical relationship or parent-child relationship.  In non-linear data structures, every data element may have more than one predecessor as well as successor.  Elements do not form any particular linear sequence.
  • 4. Non-linear data structures are capable of expressing more complex relationships than linear data structures. The memory is utilized efficiently in the non-linear data structure where linear data structure tends to waste the memory. One big drawback of linked list is, random access is not allowed.
  • 5.  Trees A tree is a non-empty set one element of which is designated the root of the tree while the remaining elements are partitioned into non-empty sets each of which is a sub-tree of the root.  Graph A graph G is a discrete structure consisting of nodes (vertices) and the lines joining the nodes (edges).
  • 6. Trees are non linear data structure that can be represented in a hierarchical manner.  A tree contains a finite non-empty set of elements.  Any two nodes in the tree are connected with a relationship of parent-child.  Every individual elements in a tree can have any number of sub trees.  It represents the nodes connected by edges
  • 7. Root : The basic node of all nodes in the tree. All operations on the tree are performed with passing root node to the functions. Child : a successor node connected to a node is called child. A node in binary tree may have at most two children.  Parent : a node is said to be parent node to all its child nodes. Leaf : a node that has no child nodes. Siblings : Two nodes are siblings if they are children to the same parent node.
  • 8. Ancestor : a node which is parent of parent node ( B is ancestor node to D,E and F ). Descendent : a node which is child of child node ( D, E and F are descendent nodes of node B )  Level : The distance of a node from the root node, The root is at level – 0,( B and C at Level 1 and D, E, F have Level 2 ( highest level of tree is called height of tree )  Degree : The number of nodes connected to a particular parent node. Path : Path is a number of successive edges from source node to destination node.
  • 9. Edge : Edge is connection between one node to another node Path : Path is a number of successive edges from source node to destination node. Edge : Edge is connection between one node to another node. Height of a node : It represents number of edges on the longest path between that node and a leaf. Height of a Tree : It represents the height of root node. Depth of a Tree: Depth of a tree represents the number edges from the tree’s root node to the node.
  • 10.  Free tree Rooted tree  Ordered tree  Regular tree  Binary tree Complete Binary tree Binary Search tree
  • 11.  A free tree is a connected, acyclic graph .  It is undirected graph  It has no node designated as a root  As it is connected, any node can be reached from any other node by a unique path Figure: Free Tree
  • 12.  Unlike free tree, rooted tree is a directed graph in which one node is designated as root, whose incoming degree is zero  And for all other nodes incoming degree is one. Figure: Rooted Tree
  • 13.  In many applications the relative order of the nodes at any particular level assumes some significance  It is easy to impose an order on the nodes at a level by referring to a particular node as the first node, to another node as the second, and so on  Such ordering can be done left to right Ordered Tree
  • 14.  A tree in which each branch node vertex has the same out degree is called as Regular Tree.  If in a directed tree, the out degree of every node is less than or equal to m, then the tree is called as an m-ary tree.  If the out degree of every node is exactly equal to m (branch nodes) or zero (leaf nodes) then the tree is called as regular m-ary tree.
  • 15. In a binary tree, each node can have at most two children. A binary tree is either empty or consists of a node called the root together with two binary trees called the left subtree and the right subtree.  Node with 2 children are called internal nodes and nodes with 0 children are called external nodes
  • 16.  Assigning level numbers and Numbering of nodes for a binary tree: The nodes of a binary tree can be numbered in a natural way level by level left to right.  The nodes of a complete binary tree can be numbered so that the root is assigned the number 1.  A left child is assigned twice the number assigned its parent.  A right child is assigned one more than twice the number assigned its parent.
  • 17.
  • 18.  If h = height of a binary tree, then a. Maximum number of leaves = 2h b. Maximum number of nodes = 2h + 1 - 1  If a binary tree contains m nodes at level l, it contains at most 2m nodes at level l + 1.  Since a binary tree can contain at most one node at level 0 (the root), it can contain at most 2l node at level l  The total number of edges in a full binary tree with n node is n - 1.
  • 19.  If every non-leaf node in a binary tree has nonempty left and right sub trees, the tree is termed a strictly binary tree.  A strictly binary tree with n leaves always contains 2n – 1 nodes.
  • 20.  A full binary tree of height h has all its leaves at level h.  All non leaf nodes of a full binary tree have two children, and the leaf nodes have no children. A full binary tree with height h has 2h + 1 - 1 nodes. A full binary tree of height h is a strictly binary tree all of whose leaves are at level h. For example, a full binary tree of height 3 contains 23+1 – 1 = 15 nodes.
  • 21.  A binary tree with n nodes is said to be complete if it contains all the first n nodes of the above numbering scheme. A complete binary tree of height h looks like a full binary tree down to level h-1, and the level h is filled from left to right. Leaf nodes at level n occupy the leftmost positions in the tree
  • 22.  A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at same level.  A Perfect Binary Tree of height h has 2h – 1 non leaf nodes.
  • 23. Array Representation In array representation of a binary tree, we use one- dimensional array (1-D Array) to represent a binary tree. This numbering can start from 0 to (n-1) or from 1 to n. Lets derive the positions of nodes and their parent and child nodes in the array. When we use 0 index based sequencing, Suppose parent node is an index p. Then, the left child node is at index (2*p)+ 1. The right child node is at index (2*p) + 2. Root node is at index 0. left_child is at index 1. Right_child is at index 2.
  • 24. When we use 1 index based sequencing, Suppose parent node is at index p, Right node is at index (2*p). Left node is at index (2*p)+1. Root node is at index 1. Left child is at index 2. Right child is at index 3. 0 1 2 3 4 5 6 7 8 9 10 11………………..20
  • 25. ADVANTAGES  Any node can be accesses from any other node by calculating the index.  Here, data are stored without any pointers to their successor or ancestor. DISADVANTAGES  Other than full binary trees, majority of the array entries may be empty  A new node to it or deleting a node from it are inefficient with this representation
  • 26. Linked List Representation  Binary trees can be represented by links where each node contains the address of the left child and the right child. If any node has its left or right child empty then it will have in its respective link field, a null value. A leaf node has null value in both of its links. Node Structure in Binary Tree
  • 27.
  • 28. ADVANTAGES  The drawback of sequential representation are overcome in this representation .  We may or may not know the tree depth in advance. Also for unbalanced tree, memory is not wasted.  Insertion and deletion operations are more efficient in this representation.
  • 29. DISADVANTAGES  In this representation, there is no direct access to any node .  It has to be traversed from root to reach to a particular node  As compared to sequential representation memory needed per node is more.  This is due to two link fields (left child and right child for binary trees) in node
  • 30. Creation : Creating an empty binary tree to which ‘root‘ points . Traversal : To Visiting all the nodes in a binary tree Deletion : To Deleting a node from a non-empty binary tree Insertion : To Inserting a node into an existing/empty binary tree. Merge : To Merging two binary trees Copy : Copying a binary tree . Compare : Comparing two binary trees. Find replica or mirror
  • 31.  A binary tree is defined recursively: it consists of a root, a left sub tree, and a right sub tree.  To traverse (or walk) the binary tree is to visit each node in the binary tree exactly once.  Tree traversals are naturally recursive.  Standard traversal orderings: • preorder • inorder • postorder
  • 32.
  • 33. In Preorder, the root is visited before (pre) the subtrees traversals.  In Inorder, the root is visited in-between left and right subtree traversal.  In Postorder, the root is visited after (post) the subtrees traversals
  • 34. Assume: visiting a node is printing its data • Preorder: 15 8 2 6 3 7 11 10 12 14 20 27 22 30 • Inorder: 2 3 6 7 8 10 11 12 14 15 20 22 27 30 • Postorder: 3 7 6 2 10 14 12 11 8 22 30 27 20 15
  • 35.  Stores keys in the nodes in a way so that searching, insertion and deletion can be done efficiently. Binary Search Tree Property For every node X, all the keys in its left subtree are smaller than the key value in X, and all the keys in its right subtree are larger than the key value in X
  • 36. Binary Tree Non Binary Tree
  • 37.
  • 38.  If we are searching for 15, then we are done. If we are searching for a key < 15, then we should search in the left subtree. If we are searching for a key > 15, then we should search in the right subtree.
  • 39.
  • 40.  FindMinimum: Start at the root and go left as long as there is a left child. The stopping point is the smallest element FindMaxmum: Start at the root and go right as long as there is a right child. The stopping point is the largest element Ascending order: Inorder traversal of a binary search tree gives prints elements in sorted order.
  • 41.  Storing naturally hierarchical data • File System • Organizational Structure of an institution • Class inheritance tree  Organize data for quick search, insertion, deletion- Binary Search Tree.  Dictionary  Networking Routing Algorithm. Problem representation • Expression trees • Decision tree.
  • 42. 1. Construct the tree from the following preorder and inorder travels: Preorder: a,b,c,d,e,g,h,j,f. Inorder: c,d,b,a,h,g,j,e,f.
  • 43. Construct a binary search tree with the below information. The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12. Preorder Traversal is 10, 4, 3, 5, 11, 12. Inorder Traversal of Binary search tree is equal to ascending order of the nodes of the Tree. Inorder Traversal is 3, 4, 5, 10, 11, 12. The tree constructed using Preorder and Inorder traversal is