A Developer's Diary

Sep 2, 2013

Find depth of the deepest odd level leaf node in a binary tree

Write a program to find maximum height of the odd level leaf node of a binary tree. The problem has been picked up from GeeksforGeeks

A quick solution will be to use the solution for finding the max depth of the tree and modifying it to calculate the depth using only the odd level leaf nodes.

Read more ...

Aug 29, 2013

Find max height of a binary tree

Program for finding maximum depth or height of a binary tree

/**
     * find height of the tree recursively
     */
    public static int maxHeight()
    {
        return maxHeight(root, 0);
    }
 
    private static int maxHeight(Node node, int h)
    {
        if (node == null)
        {
            return h;
        }
 
        int lh = maxHeight(node.left, h + 1);
        int rh = maxHeight(node.right, h + 1);
 
        return (lh > rh) ? lh : rh;
    }

Read more ...

Aug 25, 2013

Creating a binary search tree using iterative approach in Java

Program for creating a binary search tree using iterative method

private void addNode(Node node, int n)
{
    while (node != null)
    {
        if(n < node.data)
        {
            if(node.left != null)
            {
                node = node.left;
            }
            else
            {
                node.left = new Node(n);
                return;
            }
        }
        else if(n > node.data)
        {
            if(node.right != null)
            {
                node = node.right;
            }
            else
            {
                node.right = new Node(n);
                return;
            }
        }
        else
        {
            System.out.println("WARNING: Elements are equal");
            return;
        }
    }
}

Read more ...

Creating a binary search tree using recursion in Java

Program for creating binary search tree using recursive method

private void addNode(Node node, int n)
{
    if (n < node.data)
    {
        if (node.left != null)
        {
            addNode(node.left, n);
        }
        else
        {
            node.left = new Node(n);
        }
    }
    else if (n > node.data)
    {
        if (node.right != null)
        {
            addNode(node.right, n);
        }
        else
        {
            node.right = new Node(n);
        }
    }
    else
    {
        System.out.println("WARNING: Number exists already");
    }
}

Read more ...

Apr 7, 2013

An elegant navigation menu bar using css 3


In this post we will try to create an elegant navigation menu bar as shown in the image above as well as explaining the css tricks used to achieve the same.

Read more ...