SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Tree 
A tree is defined as a finite set of one or more 
nodes such that [a] There is a specially 
designated node called the root and 
[b] The rest of the nodes could be partitioned 
into t disjoint sets (t >0) each set representing 
a tree Ti, i=1,2, . . . t known as sub tree of the 
tree. 
2
Tree 
A node in the definition of the tree 
represents an item of information, 
and the links between the nodes 
termed as branches, represent an 
association between the items of 
information. 
3
A 
B C D E 
F G H I J K 
L 
Level 1 
Level 2 
Level 3 
Level 4 
4
Tree 
 Definition of Tree emphasizes on the aspect of 
[a] Connectedness, and 
[b] Absence of closed loops 
5
Basic terminologies 
degree of the node 
 leaf nodes or terminal nodes 
non terminal nodes 
 children 
 siblings 
ancestors 
degree of a tree 
hierarchical structure 
height or depth of a tree 
 forest 
6
Tree Terminology 
 A tree consists of a collection of elements or nodes, with 
each node linked to its successors 
 The node at the top of a tree is called its root 
 The links from a node to its successors are called 
branches 
 The successors of a node are called its children 
7
Tree Terminology (continued) 
 Each node in a tree has exactly one parent except for 
the root node, which has no parent 
 Nodes that have the same parent are siblings 
 A node that has no children is called a leaf node 
 A generalization of the parent-child relationship is the 
ancestor-descendent relationship 
8
Tree Terminology (continued) 
 The predecessor of a node is called its parent 
 A sub tree of a node is a tree whose root is a child of 
that node 
 The level of a node is a measure of its distance from 
the root 
9
Tree Terminology (continued) 
 Node: stores the actual data and links to other nodes 
 Parent: immediate predecessor of a node 
 Root: specially designated node which has no parent 
 Child: immediate successor of a node. 
10
Tree Terminology(continued) 
 Leaf: node without any child 
 Level: rank of the hierarchy and root node has level 
zero(0). Node at level i has the level i+1 for its child 
and i-1 for its parent. This is true for all nodes except 
the root 
11
Tree Terminology (continued) 
 Height (depth): Maximum number of nodes possible 
in a path starting from root node to leaf node. Height 
of a tree given by h = lmax, lmax is the maximum level of 
the tree. 
 Degree of node maximum number of children 
possible for a node 
 Siblings  nodes having the same parent 
12
Tree Terminology 
 Ancestor of a Node: Those nodes that occur on the 
path from the root to the given node 
 Degree of a Tree: Maximum degree of the node in the 
tree 
 Forest : A set of Zero or more Disjoint trees. 
13
A 
B C D E 
F G H I J K 
L 
Level 1 
Level 2 
Level 3 
Level 4 
Degree of the tree = 4 ( 
Max degree of A) 
Height of the tree = 4 (Max 
level) 
14
Representation of a tree 
 List Representation 
(A (B(F,G,H), C, D(I), E(J,K(L))) ) for the tree 
Considered in the Example 
15 
• Linked List Representation
DATA LINK 1 LINK 2 … LINK n 
(a) General node structure 
T 
A 
B 
C D E 
F K 
G H I 
L 
J 
(b) Linked list representation of the tree 
16
Binary Trees 
A binary tree T is defined as a finite set of elements 
called nodes such that 
[a] T is empty (Called the Null tree or Empty tree) or 
[b] T contains a distinguished node R called the root of T 
and the remaining nodes of T form an ordered pair of 
disjoint binary trees T1 and T2 
17
Binary Trees 
 A binary tree has the characteristic of all nodes 
having at most two branches, that is, all nodes have a 
degree of at most 2. 
A binary tree can therefore be empty or consist of a 
root node and two disjoint binary trees termed left 
subtree and right subtree. 
18
A 
G 
C 
D 
B 
E F 
Level 1 
Level 2 
Level 3 
19
Important observations regarding binary trees: 
 The maximum number of nodes on level i of a 
binary tree is 2i-1, i>1 
 The maximum number of nodes in a binary tree 
of height h is 2h-1, h>1 
 For any non empty binary tree, if to is the 
number of terminal nodes and t2 is the number 
of nodes of degree 2, then to=t2+1 
20
A binary tree of height h which has all its permissible 
maximum number of nodes viz., 2h-1 intact is known as a 
full binary tree of height h. 
21 
A 
G 
C 
D 
B 
E F 
1 
2 3 
4 5 
6 
7
A binary tree with n’ nodes and height h is complete 
if its nodes correspond to the nodes which are 
numbered 1 to n (n’ n) in a full binary tree of 
height h. 
22 
A 
C 
D 
B 
1 
E F 
2 
3 
4 5 6 
Height of a complete 
binary tree with n given 
by 
log ( 1) 2 h  n 
A complete binary tree obeys the following 
properties with regard to its node numbering: 
[a] If a parent node has a number i then its left 
child has the number 2i (2i < n). If 2i > n then i 
has no left child. 
[b] If a parent node has a number i, then its right 
child has the number 2i+1 (2i + 1 <n). If 2i + 1 > n 
then i has no right child. 
23
A complete binary tree obeys the following 
properties with regard to its node numbering: 
[c] If a child node (left or right) has a number i then 
the parent node has the number i /2 if i 1. If i 
=1 then i is the root and hence has no parent. 
24
A binary tree which is dominated solely by left 
child nodes or right child nodes is called a skewed 
binary tree or more specifically left skewed 
binary tree or right skewed binary tree 
respectively. 
a 
b 
c 
d 
n 
o 
m 
Left skewed Right skewed 
p 
25
Extended Binary Tree: 2-Tree 
A binary tree T is said to be 2-Tree or an extended binary 
tree if each node N has either 0 or 2 children. 
Nodes with 2 children are called internal nodes and the 
nodes with 0 children are called external nodes. 
26
Representation of Binary Tree 
Binary tree can be represented by means of 
[a] Array 
[b] linked list 
27
Representation Of Binary Trees 
Array Representation 
Sequential representation of a 
tree with depth d will require 
an array with approx 2d + 1 
elements 
28 
2 
4 5 
10 
1 
a 
c 
b 
e 
d 
f 
11 
1 2 3 4 5 6 7 8 9 10 11 
a b c d e f
Linked representation 
29 
LCHILD DATA RCHILD 
a 
b 
c d 
T 
e f
 Observation regarding the linked representation of 
Binary Tree 
[a] If a binary tree has n nodes then the number of 
pointers used in its linked representation is 2 * n 
[b] The number of null pointers used in the linked 
representation of a binary tree with n nodes is n + 1 
30
Traversing Binary Tree 
Three ways of traversing the binary tree T with root R 
Preorder 
[a] Process the root R 
[b] Traverse the left sub-tree of R in preorder 
[c] Traverse the right sub-tree of R in preorder 
31 
a. k. a node-left-right traversal (NLR)
Traversing Binary Tree 
In-order 
[a] Traverse the left sub-tree of R in in-order 
[b] Process the root R 
[c] Traverse the right sub-tree of R in in-order 
32 
a. k. a left-node-right traversal (LNR)
Traversing Binary Tree 
Post-order 
[a] Traverse the left sub-tree of R in post-order 
[b] Traverse the right sub-tree of R in post-order 
[c] Process the root R 
33 
a. k. a left-right-node traversal (LRN)
Illustrations for Traversals 
 Assume: visiting a node 
is printing its label 
 Preorder: 
1 3 5 4 6 7 8 9 10 11 12 
 Inorder: 
4 5 6 3 1 8 7 9 11 10 12 
 Postorder: 
4 6 5 3 8 11 12 10 9 7 1 
8 9 
10 
34 
1 
3 
11 
5 
4 6 
7 
12
Illustrations for Traversals (Contd.) 
 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 
6 
15 
8 
2 
3 7 
11 
10 
14 
12 
20 
27 
22 30
Formulation of Binary tree from 
Its traversal 
1. If preorder is given=>First node is the root 
If postorder is given=>Last node is the root 
2. Once the root node is identified ,all nodes in the left 
subtrees and right subtrees of the root node can be 
identified. 
3. Same technique can be applied repeatedly to form 
subtrees 
36
4.Two traversals are essential out of which one should 
inorder, another may be preorder or postorder 
5. But we can’t form a binary tree if only preorder and 
postorder has given. 
37
Example: For Given Inorder and 
Preorder 
Inorder: D B H E A I F J F CG 
Preorder: A B D E H C F I J G 
Now root is A 
Left subtree: D B H E 
Right subtree: I F J C G 
38
continues. 
A 
In:D B H E I F J C G 
Pre:B D E H C F I J G 
D H E I F J G 
E H F I J 
I J 
H 
39
Example: For Given Inorder and 
Postorder 
40 
Inorder: n1,n2, n3, n4, n5, n6, n7, n8, 
n9 
Postorder: n1,n3, n5, n4, n2, n8, n7, 
n9, n6 
So here n6 is the root
 Reference: 
 Data structure using c by Rina Thareja 
 Data structure using c by Trembly Sorenson 
 http://en.wikipedia.org/wiki/datastructure 
41
Thank you 
42

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Linked list
Linked listLinked list
Linked list
 
Huffman's algorithm in Data Structure
 Huffman's algorithm in Data Structure Huffman's algorithm in Data Structure
Huffman's algorithm in Data Structure
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
UNIT III NON LINEAR DATA STRUCTURES – TREES
UNIT III 	NON LINEAR DATA STRUCTURES – TREESUNIT III 	NON LINEAR DATA STRUCTURES – TREES
UNIT III NON LINEAR DATA STRUCTURES – TREES
 
Hash table
Hash tableHash table
Hash table
 
linked list
linked list linked list
linked list
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Red black trees
Red black treesRed black trees
Red black trees
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Red Black Tree Insertion & Deletion
Red Black Tree Insertion & DeletionRed Black Tree Insertion & Deletion
Red Black Tree Insertion & Deletion
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Binary tree
Binary tree Binary tree
Binary tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 

Andere mochten auch (20)

TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Unit8 C
Unit8 CUnit8 C
Unit8 C
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Implementation of trees
Implementation of trees Implementation of trees
Implementation of trees
 
Ch 8 introduction to data structures
Ch 8 introduction to data structuresCh 8 introduction to data structures
Ch 8 introduction to data structures
 
Lecture7 data structure(tree)
Lecture7 data structure(tree)Lecture7 data structure(tree)
Lecture7 data structure(tree)
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
 
Tree
TreeTree
Tree
 
Data structures
Data structuresData structures
Data structures
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
Tree
TreeTree
Tree
 
Data structures
Data structuresData structures
Data structures
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 

Ähnlich wie non linear data structure -introduction of tree

Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsAakash deep Singhal
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxHamzaUsman48
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
 
ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.pptkhitishlpu
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary treejyoti_lakhani
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptxAbirami A
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures treemaamir farooq
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5DrkhanchanaR
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2smruti sarangi
 

Ähnlich wie non linear data structure -introduction of tree (20)

Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
7.tree
7.tree7.tree
7.tree
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.ppt
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary tree
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5
 
07 trees
07 trees07 trees
07 trees
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 

Mehr von Siddhi Viradiya

network convergence problem and solutions
network convergence  problem and solutionsnetwork convergence  problem and solutions
network convergence problem and solutionsSiddhi Viradiya
 
Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Siddhi Viradiya
 
bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)Siddhi Viradiya
 
chapter 1 intoduction to operating system
chapter 1 intoduction to operating systemchapter 1 intoduction to operating system
chapter 1 intoduction to operating systemSiddhi Viradiya
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with exampleSiddhi Viradiya
 

Mehr von Siddhi Viradiya (7)

network convergence problem and solutions
network convergence  problem and solutionsnetwork convergence  problem and solutions
network convergence problem and solutions
 
Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)
 
bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)bus and memory tranfer (computer organaization)
bus and memory tranfer (computer organaization)
 
chapter 1 intoduction to operating system
chapter 1 intoduction to operating systemchapter 1 intoduction to operating system
chapter 1 intoduction to operating system
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with example
 
AEM Fourier series
 AEM Fourier series AEM Fourier series
AEM Fourier series
 
global warming ch-07
 global warming ch-07 global warming ch-07
global warming ch-07
 

Kürzlich hochgeladen

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Kürzlich hochgeladen (20)

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

non linear data structure -introduction of tree

  • 1.
  • 2. Tree A tree is defined as a finite set of one or more nodes such that [a] There is a specially designated node called the root and [b] The rest of the nodes could be partitioned into t disjoint sets (t >0) each set representing a tree Ti, i=1,2, . . . t known as sub tree of the tree. 2
  • 3. Tree A node in the definition of the tree represents an item of information, and the links between the nodes termed as branches, represent an association between the items of information. 3
  • 4. A B C D E F G H I J K L Level 1 Level 2 Level 3 Level 4 4
  • 5. Tree  Definition of Tree emphasizes on the aspect of [a] Connectedness, and [b] Absence of closed loops 5
  • 6. Basic terminologies degree of the node  leaf nodes or terminal nodes non terminal nodes  children  siblings ancestors degree of a tree hierarchical structure height or depth of a tree  forest 6
  • 7. Tree Terminology  A tree consists of a collection of elements or nodes, with each node linked to its successors  The node at the top of a tree is called its root  The links from a node to its successors are called branches  The successors of a node are called its children 7
  • 8. Tree Terminology (continued)  Each node in a tree has exactly one parent except for the root node, which has no parent  Nodes that have the same parent are siblings  A node that has no children is called a leaf node  A generalization of the parent-child relationship is the ancestor-descendent relationship 8
  • 9. Tree Terminology (continued)  The predecessor of a node is called its parent  A sub tree of a node is a tree whose root is a child of that node  The level of a node is a measure of its distance from the root 9
  • 10. Tree Terminology (continued)  Node: stores the actual data and links to other nodes  Parent: immediate predecessor of a node  Root: specially designated node which has no parent  Child: immediate successor of a node. 10
  • 11. Tree Terminology(continued)  Leaf: node without any child  Level: rank of the hierarchy and root node has level zero(0). Node at level i has the level i+1 for its child and i-1 for its parent. This is true for all nodes except the root 11
  • 12. Tree Terminology (continued)  Height (depth): Maximum number of nodes possible in a path starting from root node to leaf node. Height of a tree given by h = lmax, lmax is the maximum level of the tree.  Degree of node maximum number of children possible for a node  Siblings  nodes having the same parent 12
  • 13. Tree Terminology  Ancestor of a Node: Those nodes that occur on the path from the root to the given node  Degree of a Tree: Maximum degree of the node in the tree  Forest : A set of Zero or more Disjoint trees. 13
  • 14. A B C D E F G H I J K L Level 1 Level 2 Level 3 Level 4 Degree of the tree = 4 ( Max degree of A) Height of the tree = 4 (Max level) 14
  • 15. Representation of a tree  List Representation (A (B(F,G,H), C, D(I), E(J,K(L))) ) for the tree Considered in the Example 15 • Linked List Representation
  • 16. DATA LINK 1 LINK 2 … LINK n (a) General node structure T A B C D E F K G H I L J (b) Linked list representation of the tree 16
  • 17. Binary Trees A binary tree T is defined as a finite set of elements called nodes such that [a] T is empty (Called the Null tree or Empty tree) or [b] T contains a distinguished node R called the root of T and the remaining nodes of T form an ordered pair of disjoint binary trees T1 and T2 17
  • 18. Binary Trees  A binary tree has the characteristic of all nodes having at most two branches, that is, all nodes have a degree of at most 2. A binary tree can therefore be empty or consist of a root node and two disjoint binary trees termed left subtree and right subtree. 18
  • 19. A G C D B E F Level 1 Level 2 Level 3 19
  • 20. Important observations regarding binary trees:  The maximum number of nodes on level i of a binary tree is 2i-1, i>1  The maximum number of nodes in a binary tree of height h is 2h-1, h>1  For any non empty binary tree, if to is the number of terminal nodes and t2 is the number of nodes of degree 2, then to=t2+1 20
  • 21. A binary tree of height h which has all its permissible maximum number of nodes viz., 2h-1 intact is known as a full binary tree of height h. 21 A G C D B E F 1 2 3 4 5 6 7
  • 22. A binary tree with n’ nodes and height h is complete if its nodes correspond to the nodes which are numbered 1 to n (n’ n) in a full binary tree of height h. 22 A C D B 1 E F 2 3 4 5 6 Height of a complete binary tree with n given by log ( 1) 2 h  n 
  • 23. A complete binary tree obeys the following properties with regard to its node numbering: [a] If a parent node has a number i then its left child has the number 2i (2i < n). If 2i > n then i has no left child. [b] If a parent node has a number i, then its right child has the number 2i+1 (2i + 1 <n). If 2i + 1 > n then i has no right child. 23
  • 24. A complete binary tree obeys the following properties with regard to its node numbering: [c] If a child node (left or right) has a number i then the parent node has the number i /2 if i 1. If i =1 then i is the root and hence has no parent. 24
  • 25. A binary tree which is dominated solely by left child nodes or right child nodes is called a skewed binary tree or more specifically left skewed binary tree or right skewed binary tree respectively. a b c d n o m Left skewed Right skewed p 25
  • 26. Extended Binary Tree: 2-Tree A binary tree T is said to be 2-Tree or an extended binary tree if each node N has either 0 or 2 children. Nodes with 2 children are called internal nodes and the nodes with 0 children are called external nodes. 26
  • 27. Representation of Binary Tree Binary tree can be represented by means of [a] Array [b] linked list 27
  • 28. Representation Of Binary Trees Array Representation Sequential representation of a tree with depth d will require an array with approx 2d + 1 elements 28 2 4 5 10 1 a c b e d f 11 1 2 3 4 5 6 7 8 9 10 11 a b c d e f
  • 29. Linked representation 29 LCHILD DATA RCHILD a b c d T e f
  • 30.  Observation regarding the linked representation of Binary Tree [a] If a binary tree has n nodes then the number of pointers used in its linked representation is 2 * n [b] The number of null pointers used in the linked representation of a binary tree with n nodes is n + 1 30
  • 31. Traversing Binary Tree Three ways of traversing the binary tree T with root R Preorder [a] Process the root R [b] Traverse the left sub-tree of R in preorder [c] Traverse the right sub-tree of R in preorder 31 a. k. a node-left-right traversal (NLR)
  • 32. Traversing Binary Tree In-order [a] Traverse the left sub-tree of R in in-order [b] Process the root R [c] Traverse the right sub-tree of R in in-order 32 a. k. a left-node-right traversal (LNR)
  • 33. Traversing Binary Tree Post-order [a] Traverse the left sub-tree of R in post-order [b] Traverse the right sub-tree of R in post-order [c] Process the root R 33 a. k. a left-right-node traversal (LRN)
  • 34. Illustrations for Traversals  Assume: visiting a node is printing its label  Preorder: 1 3 5 4 6 7 8 9 10 11 12  Inorder: 4 5 6 3 1 8 7 9 11 10 12  Postorder: 4 6 5 3 8 11 12 10 9 7 1 8 9 10 34 1 3 11 5 4 6 7 12
  • 35. Illustrations for Traversals (Contd.)  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 6 15 8 2 3 7 11 10 14 12 20 27 22 30
  • 36. Formulation of Binary tree from Its traversal 1. If preorder is given=>First node is the root If postorder is given=>Last node is the root 2. Once the root node is identified ,all nodes in the left subtrees and right subtrees of the root node can be identified. 3. Same technique can be applied repeatedly to form subtrees 36
  • 37. 4.Two traversals are essential out of which one should inorder, another may be preorder or postorder 5. But we can’t form a binary tree if only preorder and postorder has given. 37
  • 38. Example: For Given Inorder and Preorder Inorder: D B H E A I F J F CG Preorder: A B D E H C F I J G Now root is A Left subtree: D B H E Right subtree: I F J C G 38
  • 39. continues. A In:D B H E I F J C G Pre:B D E H C F I J G D H E I F J G E H F I J I J H 39
  • 40. Example: For Given Inorder and Postorder 40 Inorder: n1,n2, n3, n4, n5, n6, n7, n8, n9 Postorder: n1,n3, n5, n4, n2, n8, n7, n9, n6 So here n6 is the root
  • 41.  Reference:  Data structure using c by Rina Thareja  Data structure using c by Trembly Sorenson  http://en.wikipedia.org/wiki/datastructure 41