Nov 8, 2018

Binary tree should be remembered for Java interview

Each node contains a left node and right node like the following:
class TreeNode{
 int value;
 TreeNode left;
 TreeNode right;

  • Binary Search Tree: for all nodes, left children <= current node <= right children
  • Balanced tree the depth of the left and right subtrees of every node differ by 1 or less.
  • Full Binary Tree: every node other than the leaves has two children.
  • Perfect Binary Tree: a full binary tree in which all leaves are at the same depth or same level, and in which every parent has two children.
  • Complete Binary Tree: a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible