Module 11 TREES
Module 11 TREES
T REES
• Degree of a Node
The degree of a node is the total
number of branches of that
node.
• Forest
A collection of disjoint trees is
called a forest.
Types of Tree
1.Binary Tree
2.Binary Search Tree
3.AVL Tree
4.B-Tree
Tree Traversal
• In order to perform any operation on a tree, you need to reach
to the specific node. The tree traversal algorithm helps in
visiting a required node in the tree.
• Tree traversing in Python refers to the process of visiting each
node in a data structure like a tree. Traversal algorithms tell us
the order in which the nodes of a tree are visited.
• Now, there are 3 main methods for Tree Traversal in Python
with recursion using DFS which are:
1. In order Traversal (left, root, right)
2.Preorder Traversal (root, left, right)
3.Postorder Traversal (left, right, root)
Inorder Tree Traversal
• Using the in-order traversal method, we first visit
the left subtree of the original tree. Then we will
traverse the root node of the tree and lastly the
right subtree of the original tree. Here is the
algorithm for Inorder Tree Traversal in Python:
1.Calling Inorder (left-subtree)
2.Visit the root node
3.Calling Inorder (right subtree)
Inorder Tree Traversal (left,
root, right)
Preorder Tree Traversal