Binary Tree
Last updated
Last updated
A binary tree is a tree data structure composed of nodes, each of which has at most, two children, referred to as left and right nodes.
The tree starts off with a single node known as the root.
Data
Pointer to the left child
Pointer to the right child
In case of a leaf node, the pointers to the left and right child point to null
A full Binary tree is a special type of binary tree in which every parent node/internal node has either two or no children.
A perfect binary tree is a type of binary tree in which every internal node has exactly two child nodes and all the leaf nodes are at the same level.
A complete binary tree is a binary tree in which all the levels are completely filled except possibly the lowest one, which is filled from the left.
A complete binary tree is just like a full binary tree, but with two major differences:
All the leaf elements must lean towards the left.
The last leaf element might not have a right sibling i.e. a complete binary tree doesn't have to be a full binary tree.