private Node<T> splay(Node<T> root, String relationship) {

        //if supplied node is already root node
        if(relationship==""){
            return root;
        }

        // if the supplied node is either direct left or direct right child of the root
        if(relationship.length()==1){
            //fetch last character of relationship
            switch(relationship) {
                case "0" :
                    //apply right rotation
                    root = rotateRight(root);
                    // delete the last character from relationship
                    relationship = relationship.substring(0, relationship.length()-1);
                    break;

                case "1" :
                    //apply left rotation
                    root = rotateLeft(root);
                    // delete the last character from relationship
                    relationship = relationship.substring(0, relationship.length()-1);
                    break;
            }
        }
        // if the supplied node lives far from the root .. consider parent and grandparent only
        else {

            // fetch last 2 characters from relationship
            switch(relationship.substring(relationship.length()-2)) {

                case "00" :
                    //left child of left child .. apply zag zag
                    //rotate the parent to right
                    root = rotateRight(root.parent);
                    //since the parent has become root.. now rotate the left child which is the original node to right
                    root = rotateRight(root.left);
                    // delete the last 2 characters from relationship
                    relationship = relationship.substring(0, relationship.length()-2);
                    break;

                case "11" :
                    //right child of right child  .. apply zig zig
                    //left rotate the parent
                    root = rotateLeft(root.parent);
                    //since the parent has become root.. now rotate the right child which is the original node to left
                    root = rotateLeft(root.right);
                    // delete the last 2 characters from relationship
                    relationship = relationship.substring(0, relationship.length()-2);
                    break;
                case "01" :
                    //right child of left child .. apply zig zag
                    // left rotate the root
                    root = rotateLeft(root);
                    // right rotate the root
                    root  = rotateRight(root);

                    // delete the last 2 characters from relationship
                    relationship = relationship.substring(0, relationship.length()-2);
                    break;
                case "10" :
                    // left child of right child  .. apply zag zig
                    //right rotate the root
                    root  = rotateRight(root);
                    // now left rotate
                    root = rotateLeft(root);

                    // delete the last 2 characters from relationship
                    relationship = relationship.substring(0, relationship.length()-2);
                    break;

            }

        }

        //recursively call the splay method till the root supplied becomes the root of the actual tree
        while(root.parent!=null){
            root = splay(root,relationship);
        }

        return root;
    }