SlideShare una empresa de Scribd logo
1 de 23
TREE
Fariha Tasmin Jaigirdar
Assistant Professor
Daffodil International University
TREE
 Trees are very flexible and powerful non-liner data structure that
can be used to represent data items possessing hierarchical
relationship between the grand father and his children and grand
children as so on.
 A tree is an ideal data structure for representing hierarchical data.
 A tree can be theoretically defined as a finite set of one or more
data items (or nodes) such that :
1. There is a special node called the root of the tree.
2. Removing nodes (or data item) are partitioned into number of mutually
exclusive (i.e., disjoined) subsets each of which is itself a tree, are called
sub tree.
 Before we begin our study of tree data structures, let’s look at a
few common examples.
EXAMPLES OF TREES
 Our first example of a
tree is a classification
tree from biology.
Figure 1: Taxonomy of Some Common Animals Shown as a Tree
EXAMPLES OF TREES
 Another example of a tree structure that you probably use
every day is a file system.
 In a file system, directories, or folders, are structured as a
tree.
 Figure 2 illustrates a small part of a Unix file system hierarchy.
Figure 2: A Small Part of the Unix File System Hierarchy
EXAMPLES OF TREES
 A final example of a tree is a web page. The following is
an example of a simple web page written using HTML.
 Figure shows the tree that corresponds to each of the
HTML tags used to create the page.
Figure 3: A Tree Corresponding to the Markup Elements of a Web Page
BASIC TERMINOLOGIES
 Node : A node is a fundamental part of a tree. Each letter
represents one node
 It can have a name.
 A node may also have additional information.
 Edge : the arrows from one node to another are called edges
 An edge connects two nodes to show that there is a relationship between
them.
 Every node (except the root) is connected by exactly one incoming edge
from another node.
 Each node may have several outgoing edges.
Figure 4: Picture of a tree of letters.
BASIC TERMINOLOGIES
 Root : the topmost node (with no incoming edges) is the
root.
 The root of the tree is the only node in the tree that has no
incoming edges.
 Example
 In Figure 4, node A is the root node of the tree
 In Figure 2, / is the root of the tree.
 Leaf Node : A leaf node is a node that has no children.
 The bottom nodes (with no outgoing edges) are the leaves
 Example
 In Figure 4, nodes D, I, G & J are leaf nodes
 in Figure 1, Human and Chimpanzee are leaf nodes.
BASIC TERMINOLOGIES
 Path : A path in a tree is a sequence of (zero or more)
connected nodes;
 Example, here are 3 of the paths in the tree shown in Figure:
 The length of a path is the number of nodes in the path,
e.g.:
BASIC TERMINOLOGIES
 Given two connected nodes like this:
 Node A is called the parent, and node B is called the child.
 Children
 The set of nodes c that have incoming edges from the same node to
are said to be the children of that node.
 In Figure 2, nodes log/, spool/, and yp/ are the children of node var/.
 Parent
 A node is the parent of all the nodes it connects to with outgoing
edges.
 In Figure 2 the node var/ is the parent of nodes log/, spool/, and yp/.
 Sibling
 Nodes in the tree that are children of the same parent are said to be
siblings.
 The nodes etc/ and usr/ are siblings in the file system tree.
BASIC TERMINOLOGIES
 Subtree: A subtree of a given node includes one of its children
and all of that child's descendants.
 The descendants of a node n are all nodes reachable from n (n's
children, its children's children, etc.).
 In the example Figure 4, node A has three subtrees:
① B, D
② I
③ C, E, F, G, J.
 Level
 The level of a node n is the number of edges on the path from the root
node to n.
 Example, the level of the Felis node in Figure 1 is five.
 By definition, the level of the root node is zero.
 Height
 The height of a tree is equal to the maximum level of any node in the
tree.
 The height of the tree in Figure 2 is two.
BASIC TERMINOLOGIES
 Depth
 depth tells the number of steps (nodes) to get from a node back
to the root.
 This tree has height 5, so the maximum depth is 4 (height - 1)
TREE CONT.
Figure 5: A sample Tree of latters
BASIC TERMINOLOGIES
 Root is a specially designed node (or data items) in a tree. It is the first node
in the hierarchical arrangement of the data items. ‘A’ is a root node in the Fig.
8.1. Each data item in a tree is called a node. It specifies the data information
and links (branches) to other data items.
Figure 5
CLASSIFICATION OF TREE
BINARY TREES
BINARY TREES
STRICTLY BINARY TREE
COMPLETE BINARY TREE
TRAVERSING BINARY TREES
PRE ORDERS TRAVERSAL
 To traverse a non-empty binary
tree in pre order following steps
one to be processed
1. Visit the root node
2. Traverse the left sub tree in
preorder
3. Traverse the right sub tree in
preorder
 That is, in preorder traversal, the
root node is visited (or processed)
first, before traveling through left
and right sub trees recursively.
IN ORDER TRAVERSAL
 The in order traversal of a non-
empty binary tree is defined as
follows :
1. Traverse the left sub tree in order
2. Visit the root node
3. Traverse the right sub tree in order
 In order traversal, the left sub
tree is traversed recursively,
before visiting the root. After
visiting the root the right sub tree
is traversed recursively, in order
fashion.
The in order traversal of a binary tree in Fig. 8.12 is D, B, H, E, I, A, F, C, J,
G.
POST ORDER TRAVERSAL
 The post order traversal of a
non-empty binary tree can be
defined as :
1. Traverse the left sub tree in post
order
2. Traverse the right sub tree in post
order
3. Visit the root node
 In Post Order traversal, the left
and right sub tree(s) are
recursively processed be- fore
visiting the root.
The post order traversal of a binary tree in Fig. 8.12 is D, H, I, E, B, F, J, G, C,
A
INORDER, PREORDER AND POSTORDER

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Trees
TreesTrees
Trees
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
Tree
TreeTree
Tree
 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
 
Tree
TreeTree
Tree
 
Ch13 Binary Search Tree
Ch13 Binary Search TreeCh13 Binary Search Tree
Ch13 Binary Search Tree
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
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
 
07 trees
07 trees07 trees
07 trees
 
Data structure tree - beginner
Data structure tree - beginnerData structure tree - beginner
Data structure tree - beginner
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Trees - Non Linear Data Structure
Trees - Non Linear Data StructureTrees - Non Linear Data Structure
Trees - Non Linear Data Structure
 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
 
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
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Tree data structure
Tree data structureTree data structure
Tree data structure
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 

Destacado (16)

En el siglo xviii lo que hoy a prin...
En el siglo  xviii lo que hoy                                          a prin...En el siglo  xviii lo que hoy                                          a prin...
En el siglo xviii lo que hoy a prin...
 
Diego fernando lozada garnica
Diego fernando lozada garnicaDiego fernando lozada garnica
Diego fernando lozada garnica
 
Queue
QueueQueue
Queue
 
Catellano
CatellanoCatellano
Catellano
 
Graphs
GraphsGraphs
Graphs
 
CV_Gaurav Mohite
CV_Gaurav MohiteCV_Gaurav Mohite
CV_Gaurav Mohite
 
和歌山五日
和歌山五日和歌山五日
和歌山五日
 
variables aleatorias (1)
 variables aleatorias (1) variables aleatorias (1)
variables aleatorias (1)
 
.
..
.
 
Educational objectives
Educational  objectivesEducational  objectives
Educational objectives
 
Plantas Haddock Business
Plantas Haddock BusinessPlantas Haddock Business
Plantas Haddock Business
 
Guia de ejercicios hipotesis
Guia de ejercicios hipotesisGuia de ejercicios hipotesis
Guia de ejercicios hipotesis
 
Global illumination
Global illuminationGlobal illumination
Global illumination
 
Engenharia do Produto - Marcel Gois
Engenharia do Produto - Marcel GoisEngenharia do Produto - Marcel Gois
Engenharia do Produto - Marcel Gois
 
Unit 11 where do we live
Unit 11 where do we liveUnit 11 where do we live
Unit 11 where do we live
 
Innovative Methods and Technologies in Project Management: Project Management...
Innovative Methods and Technologies in Project Management: Project Management...Innovative Methods and Technologies in Project Management: Project Management...
Innovative Methods and Technologies in Project Management: Project Management...
 

Similar a Tree

Similar a Tree (20)

UNIT-4 TREES.ppt
UNIT-4 TREES.pptUNIT-4 TREES.ppt
UNIT-4 TREES.ppt
 
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
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 
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
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 
tree traversals.pdf
tree traversals.pdftree traversals.pdf
tree traversals.pdf
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Unit 3,4.docx
Unit 3,4.docxUnit 3,4.docx
Unit 3,4.docx
 
Trees - Data structures in C/Java
Trees - Data structures in C/JavaTrees - Data structures in C/Java
Trees - Data structures in C/Java
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Trees
TreesTrees
Trees
 
Unit II,III - Data Structures.pdf
Unit II,III - Data Structures.pdfUnit II,III - Data Structures.pdf
Unit II,III - Data Structures.pdf
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Ch12 Tree
Ch12 TreeCh12 Tree
Ch12 Tree
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Lecture 5 trees
Lecture 5 treesLecture 5 trees
Lecture 5 trees
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 

Más de Himadri Sen Gupta (7)

Report of industrial training
Report of industrial trainingReport of industrial training
Report of industrial training
 
Binary search trees (1)
Binary search trees (1)Binary search trees (1)
Binary search trees (1)
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
14 recursion
14 recursion14 recursion
14 recursion
 
Heap
HeapHeap
Heap
 
Linked lists
Linked listsLinked lists
Linked lists
 
1311004
13110041311004
1311004
 

Último

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
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
 
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
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(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
 
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
 
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
 
(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
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 

Último (20)

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
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
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
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
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(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...
 
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
 
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
 
(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
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

Tree

  • 1. TREE Fariha Tasmin Jaigirdar Assistant Professor Daffodil International University
  • 2. TREE  Trees are very flexible and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and grand children as so on.  A tree is an ideal data structure for representing hierarchical data.  A tree can be theoretically defined as a finite set of one or more data items (or nodes) such that : 1. There is a special node called the root of the tree. 2. Removing nodes (or data item) are partitioned into number of mutually exclusive (i.e., disjoined) subsets each of which is itself a tree, are called sub tree.  Before we begin our study of tree data structures, let’s look at a few common examples.
  • 3. EXAMPLES OF TREES  Our first example of a tree is a classification tree from biology. Figure 1: Taxonomy of Some Common Animals Shown as a Tree
  • 4. EXAMPLES OF TREES  Another example of a tree structure that you probably use every day is a file system.  In a file system, directories, or folders, are structured as a tree.  Figure 2 illustrates a small part of a Unix file system hierarchy. Figure 2: A Small Part of the Unix File System Hierarchy
  • 5. EXAMPLES OF TREES  A final example of a tree is a web page. The following is an example of a simple web page written using HTML.  Figure shows the tree that corresponds to each of the HTML tags used to create the page. Figure 3: A Tree Corresponding to the Markup Elements of a Web Page
  • 6. BASIC TERMINOLOGIES  Node : A node is a fundamental part of a tree. Each letter represents one node  It can have a name.  A node may also have additional information.  Edge : the arrows from one node to another are called edges  An edge connects two nodes to show that there is a relationship between them.  Every node (except the root) is connected by exactly one incoming edge from another node.  Each node may have several outgoing edges. Figure 4: Picture of a tree of letters.
  • 7. BASIC TERMINOLOGIES  Root : the topmost node (with no incoming edges) is the root.  The root of the tree is the only node in the tree that has no incoming edges.  Example  In Figure 4, node A is the root node of the tree  In Figure 2, / is the root of the tree.  Leaf Node : A leaf node is a node that has no children.  The bottom nodes (with no outgoing edges) are the leaves  Example  In Figure 4, nodes D, I, G & J are leaf nodes  in Figure 1, Human and Chimpanzee are leaf nodes.
  • 8. BASIC TERMINOLOGIES  Path : A path in a tree is a sequence of (zero or more) connected nodes;  Example, here are 3 of the paths in the tree shown in Figure:  The length of a path is the number of nodes in the path, e.g.:
  • 9. BASIC TERMINOLOGIES  Given two connected nodes like this:  Node A is called the parent, and node B is called the child.  Children  The set of nodes c that have incoming edges from the same node to are said to be the children of that node.  In Figure 2, nodes log/, spool/, and yp/ are the children of node var/.  Parent  A node is the parent of all the nodes it connects to with outgoing edges.  In Figure 2 the node var/ is the parent of nodes log/, spool/, and yp/.  Sibling  Nodes in the tree that are children of the same parent are said to be siblings.  The nodes etc/ and usr/ are siblings in the file system tree.
  • 10. BASIC TERMINOLOGIES  Subtree: A subtree of a given node includes one of its children and all of that child's descendants.  The descendants of a node n are all nodes reachable from n (n's children, its children's children, etc.).  In the example Figure 4, node A has three subtrees: ① B, D ② I ③ C, E, F, G, J.  Level  The level of a node n is the number of edges on the path from the root node to n.  Example, the level of the Felis node in Figure 1 is five.  By definition, the level of the root node is zero.  Height  The height of a tree is equal to the maximum level of any node in the tree.  The height of the tree in Figure 2 is two.
  • 11. BASIC TERMINOLOGIES  Depth  depth tells the number of steps (nodes) to get from a node back to the root.  This tree has height 5, so the maximum depth is 4 (height - 1)
  • 12. TREE CONT. Figure 5: A sample Tree of latters
  • 13. BASIC TERMINOLOGIES  Root is a specially designed node (or data items) in a tree. It is the first node in the hierarchical arrangement of the data items. ‘A’ is a root node in the Fig. 8.1. Each data item in a tree is called a node. It specifies the data information and links (branches) to other data items. Figure 5
  • 20. PRE ORDERS TRAVERSAL  To traverse a non-empty binary tree in pre order following steps one to be processed 1. Visit the root node 2. Traverse the left sub tree in preorder 3. Traverse the right sub tree in preorder  That is, in preorder traversal, the root node is visited (or processed) first, before traveling through left and right sub trees recursively.
  • 21. IN ORDER TRAVERSAL  The in order traversal of a non- empty binary tree is defined as follows : 1. Traverse the left sub tree in order 2. Visit the root node 3. Traverse the right sub tree in order  In order traversal, the left sub tree is traversed recursively, before visiting the root. After visiting the root the right sub tree is traversed recursively, in order fashion. The in order traversal of a binary tree in Fig. 8.12 is D, B, H, E, I, A, F, C, J, G.
  • 22. POST ORDER TRAVERSAL  The post order traversal of a non-empty binary tree can be defined as : 1. Traverse the left sub tree in post order 2. Traverse the right sub tree in post order 3. Visit the root node  In Post Order traversal, the left and right sub tree(s) are recursively processed be- fore visiting the root. The post order traversal of a binary tree in Fig. 8.12 is D, H, I, E, B, F, J, G, C, A