Tree
Presented by:
Shatabdi Shil Piu
ID: 201-15-3421
Section: PC I
Basic
A
B C
D E
Node:
A node is an entity
that contains a key
or value and
pointers to its child
nodes.
A
B C
D E
Edge:
It is the link between
any two nodes.
A
B C
D E
Root
It is the topmost
node of a tree.
root
A
B C
D E
Height of a
Node
The height of a node
is the number of
edges from the node
to the deepest leaf
Depth of a
Node
The depth of a node
is the number of
edges from the root
to the node.
Height 2
Height 1
Height 0
Depth 0
Depth 1
Depth 2
A
B C
D E
Parent :
Any node except the
root node has one
edge upward to a
node called parent.
Child :
The node below a
given node
connected by its edge
downward is called
its child node.
Child Node
Parent Node
siblings
Tree Traversals
Depth First
Traversals
Inorder Traversal
Preorde Traversal
Postorder Traversal
Breadth First or
Level Order
Traversal
1
2 3
4 5
1.Inorder
 First, visit all the
nodes in the left sub-
tree
 Then the root node
 Visit all the nodes in
the right sub-tree
left-> root-> right
1
2 3
4 5
InorderTraversals
4-> 2-> 5-> 1-> 3
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
2.Preorder
 Visit root node
 Visit all the nodes in
the left subtree
 Visit all the nodes in
the right subtree
root-> left-> right
1
2 3
4 5
Preorder Traversals
1-> 2-> 4-> 5-> 3
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
3.Postorder
 Visit all the nodes in
the left subtree
 Visit all the nodes in
the right subtree
 Visit the root node
left-> right->root
1
2 3
4 5
Postorder Traversals
4-> 5-> 2-> 3-> 1
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
Tree Traversals
Breadth First or
Level Order
Traversal
1
2 3
4 5
Breadth First or Level
Order Traversal
1->2-> 3-> 4-> 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
1
2 3
4 5
Thaharim Khan
Lecturer
Department of Computer Science and
Engineering
Daffodil International University
Thank You

Tree Data Structure: Concepts, Types, and Algorithms

  • 1.
    Tree Presented by: Shatabdi ShilPiu ID: 201-15-3421 Section: PC I
  • 2.
    Basic A B C D E Node: Anode is an entity that contains a key or value and pointers to its child nodes.
  • 3.
    A B C D E Edge: Itis the link between any two nodes.
  • 4.
    A B C D E Root Itis the topmost node of a tree. root
  • 5.
    A B C D E Heightof a Node The height of a node is the number of edges from the node to the deepest leaf Depth of a Node The depth of a node is the number of edges from the root to the node. Height 2 Height 1 Height 0 Depth 0 Depth 1 Depth 2
  • 6.
    A B C D E Parent: Any node except the root node has one edge upward to a node called parent. Child : The node below a given node connected by its edge downward is called its child node. Child Node Parent Node siblings
  • 7.
    Tree Traversals Depth First Traversals InorderTraversal Preorde Traversal Postorder Traversal Breadth First or Level Order Traversal
  • 8.
    1 2 3 4 5 1.Inorder First, visit all the nodes in the left sub- tree  Then the root node  Visit all the nodes in the right sub-tree left-> root-> right
  • 9.
    1 2 3 4 5 InorderTraversals 4->2-> 5-> 1-> 3 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
  • 10.
    1 2 3 4 5 2.Preorder Visit root node  Visit all the nodes in the left subtree  Visit all the nodes in the right subtree root-> left-> right
  • 11.
    1 2 3 4 5 PreorderTraversals 1-> 2-> 4-> 5-> 3 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
  • 12.
    1 2 3 4 5 3.Postorder Visit all the nodes in the left subtree  Visit all the nodes in the right subtree  Visit the root node left-> right->root
  • 13.
    1 2 3 4 5 PostorderTraversals 4-> 5-> 2-> 3-> 1 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
  • 14.
    1 2 3 4 5 TreeTraversals Breadth First or Level Order Traversal
  • 15.
    1 2 3 4 5 BreadthFirst or Level Order Traversal 1->2-> 3-> 4-> 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
  • 16.
    Thaharim Khan Lecturer Department ofComputer Science and Engineering Daffodil International University
  • 17.