Gate CS-2012 Question Paper With Solutions

Q. 47 The height of a tree is defined as the number of edges on the longest path in the
tree. The function shown in the pseudocode below is invoked as height(root)
to compute the height of a binary tree rooted at the tree pointer root.
Gate CS-2012 Question Paper With Solutions
The appropriate expression for the two boxes B1 and B2 are

(A) B1 : (1 + height(n->right)), B2 : (1 + max(h1,h2))

(B) B1 : (height(n->right)), B2 : (1 + max(h1,h2))

(C) B1 : height(n->right), B2 : max(h1,h2)

(D) B1 : (1 + height(n->right)), B2 : max(h1,h2)

Answer: (A)

Explanation:

Gate CS-2012 Question Paper With Solutions

Learn More:   Gate ME-2010 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here