Binary tree utilities

Height of binary tee

Longest path from the root the leaves.

/**
     * Find the height of the binary tree given the root node.
     * @param root
     * @return Height of the longest path.
     */
    protected int computeHeight(Node root){
        if(null 
read the rest.

Binary tree traversals (Java implementation)

Traversing binary tree. Since tree is a graph, both the depth first traversal and the breadth first traversal idea works.

  • Depth first traversal – 3 classes. Time complexity – O(n) where n is number of nodes.
    • InOrder traversal – Order
read the rest.

Binary tree

Notes on Binary Tree

  • Tree with max 2 children in each node.
  • The maximum number of nodes at level ā€˜lā€™ of a binary tree is 2^(l-1). Level of root is 1.
  • Maximum number of nodes in a binary tree of
read the rest.