Learn Simpli

Free Online Tutorial For Programmers, Contains a Solution For Question in Programming. Quizzes and Practice / Company / Test interview Questions.

Binary Tree

data structure - binary tree

What is a binary tree?
  1. The binary tree starts from the root node
  2. The root node has no parent
  3. Nodes have at most two children or 1 or 0
  4. We refer to the children as left and right
  5. They are recursively defined
  6. Every node in the tree can itself be brought of as the root node of the smaller distinct tree
  7. Edges connect the nodes
  8. The degree of the tree is its max children counts
  9. The height of the tree is calculated by all of its child paths
  10. 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
  1. A perfect binary tree is a binary tree where all the leaf node are full
  2. 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