#Day26 #100DaysOfCode
Complete Binary Tree is constructed like the heap data structure. It iteratively inserts the nodes from the left where a parent node has a 2 children array indexes are 2i+1 and 2i+2. To check whether a node is from which parent, get the node index (i-1)/2 is the parent index.
However, to check whether a binary search tree is a complete BT, there are some specific conditions:
_ every node at each level must be filled, except the last level, which is the leaves.
_ the leaves should lean towards the left. there shouldn't be a node that only have a right branch. Nodes either have 2 children, 1 left child, or no children at all, continuously, 1 left child is allowed as the last leaf, but not alternatively.
Complete Binary Tree is constructed like the heap data structure. It iteratively inserts the nodes from the left where a parent node has a 2 children array indexes are 2i+1 and 2i+2. To check whether a node is from which parent, get the node index (i-1)/2 is the parent index.
However, to check whether a binary search tree is a complete BT, there are some specific conditions:
_ every node at each level must be filled, except the last level, which is the leaves.
_ the leaves should lean towards the left. there shouldn't be a node that only have a right branch. Nodes either have 2 children, 1 left child, or no children at all, continuously, 1 left child is allowed as the last leaf, but not alternatively.