Binary Tree
Binary Tree is one of the starting part of non-linear data structure, it is one of the key concepts of Data Structures. In Binary Tree data is stored in Hierarchical order. Binary Tree is defined as a Tree data structure with 2 nodes right or left along with the data element. Each node have at most two nodes left or right.
Why we study?
The reason is Sorting. Binary search trees, a variant of binary trees are used in the implementation of sorting algorithms to order items. A binary search tree is simply an ordered or sorted binary tree such that the value in the left child is less than the value in the parent node.
In binary tree there is no guarantee of sorted data which means, sometimes data stored in sorted manner or sometimes not, it's totally depended on the way of insertion.
Types of Binary Tree
- Balanced Binary Tree
- Full Binary Tree
- Perfect Binary Tree
- Complete Binary Tree
- Degenerate Binary Tree and many more...
Terminologies associated with Binary Tree
- Root
- Node
- Parent - The node who have a sub-node of its own.
- Child - Who came from the other node.
- Leaf Node - The node who doesn't have any child.
Traversals are the key point of Binary Tree, if you have knowledge about traversals in Binary tree then you can solve any problem related to Binary Tree with some own logics.
Some famous Traversals which have major role:
- In-order Traversal
- Preorder Traversal
- Post Order Traversal
- Vertical Order Traversal
- Morris Traversal
The catch on the above traversals is preorder, in-order, post-order as well as vertical order have space complexity is big o(n) but in the Morris traversal space complexity is big O(1) because Morris traversal work on the Binary thread concept.
If you learnt above points and concepts genuinely then you have to move forward and solve the famous questions on the various platform such as leetcode easily.