Notes

Binary Trees

graphs
graphs
tree
tree
class TreeNode {
  constructor(val) {
    this.val = val;
    this.left = null;
    this.right = null;
  }
}

a.left = b;
a.right = c;
b.left = d;
b.right = e;
c.right = f;

Basic Tree Terminology

Traversing Trees

        A
       / \
      B   C
     /   / \
    D   E   F
 A, B, C, D, E, F
        A
       / \
      B   C
     /   / \
    D   E   F
 A, B, D, C, E, F
pic
pic

Binary Search Trees

bst
bst
function inOrderPrint(root) {
  if (!root) return;

  inOrderPrint(root.left);
  console.log(root.val);
  inOrderPrint(root.right);
}
// BST 1: 42
// BST 2: 4, 5, 6
// BST 3: 1, 5, 7, 10, 16, 16