A binary tree is defined as finite set of elements called nodes such that the tree contains a distinguished node called root of the tree and the remaining nodes form a ordered pair of disjoint binary tree T1 T2
Every node contain atmost 2 child
The degree of binary tree highest possible is 2
In short binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
- Check if the current node is empty or null.
- Display the data part of the root (or current node).
- Traverse the left subtree by recursively calling the pre-order function.
- Traverse the right subtree by recursively calling the pre-order function.
Pre-order: F, B, A, D, C, E, G, I, H
- Check if the current node is empty or null.
- Traverse the left subtree by recursively calling the in-order function.
- Display the data part of the root (or current node).
- Traverse the right subtree by recursively calling the in-order function.
In-order: A, B, C, D, E, F, G, H, I
In a binary search tree, in-order traversal retrieves data in sorted order
- Check if the current node is empty or null.
- Traverse the left subtree by recursively calling the post-order function.
- Traverse the right subtree by recursively calling the post-order function.
- Display the data part of the root (or current node).