Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2012
Questions

Q47

MCQ2 marks, −0.67Data structuresMedium

The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root.

int height(treeptr n)
{ if(n == NULL) return -1;
    if(n -> left == NULL)
        if(n -> right == NULL) return 0;
        else return B1; // Box 1
    else{h1 = height(n -> left);
        if(n -> right == NULL) return (1+h1);
        else{h2 = height(n -> right);
            return B2; // Box 2
        }
    }
}

The appropriate expressions for the two boxes B1 and B2 are:

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.