Binary Tree - Types and Traversal

Some of the common types of Binary Tree are listed below :

Full Binary Tree 
- In a full binary tree, each node has either 0 or 2 children.
- Each node is either leaf or has exactly 2 children.



Complete Binary Tree 
- All levels are full except possibly last.
- All nodes in the last level are aligned towards the left. 





Perfect Binary Tree 
- All nodes have 2 children except leaf.
- All leaf nodes are at the same level.


Balanced Binary Tree 
- Very good performance, O(log n) Insertion, Deletion and Search
- Every level above the lowest is full
- Diff is maximum 1 between left subtree and right subtree



Degenerate/Pathological Binary Tree 
- Each node has one child except leaf


Traversal


Preorder
Node is visited before its left and right subtrees

Postorder
Node is visited after both subtrees

Inorder
Visit left subtree, then visit node and finally right subtree





Binary Tree Traversals can be implemented by using recursive functions. 

Comments

Popular posts from this blog

In Place Algorithms

References in C++