Binary Tree
What is a binary tree?
- The binary tree starts from the root node
- The root node has no parent
- Nodes have at most two children or 1 or 0
- We refer to the children as left and right
- They are recursively defined
- Every node in the tree can itself be brought of as the root node of the smaller distinct tree
- Edges connect the nodes
- The degree of the tree is its max children counts
- The height of the tree is calculated by all of its child paths
- The root node has level one
Define binary tree node
Let’s look how binary tree node looks like
// Binary tree node in javascript function BinaryTreeNode(data) { this.data = data; this.left = null; this.right = null; }
Perfect binary tree
- A perfect binary tree is a binary tree where all the leaf node are full
- In other words, the node has zero or 2 children
Full binary tree
A perfect binary tree is a binary tree where the child has either 0 or 2 children but not one child