1
GATE CSE 2014 Set 3
+2
-0.6
Consider the pseudocode given below. The function Dosomething () takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChild-rightSibling representation. Each node of the tree is of type treeNode.
typedef struct treeNode* treeptr;
Struct treeNode
{
Treeptr leftMostchild, rightSibiling;
};
Int Dosomething (treeptr tree)
{
int value =0;
if (tree ! = NULL) {
If (tree -> leftMostchild = = NULL)
value=1;
else
value = Dosomething (tree->leftMostchild);
value = value + Dosometing (tree->rightsibiling);
}
return (value);
}
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned by the function corresponds to the
A
number of internal nodes in the tree.
B
height of the tree
C
number of nodes without a right sibling in the tree.
D
number of leaf nodes in the tree.
2
GATE CSE 2014 Set 3
Numerical
+2
-0
Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is O( na logb n + mc logd n ), the value of a + 10b + 100c + 1000d is _______.
3
GATE CSE 2012
+2
-0.6
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.
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 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 : height(n->right), B2 : max(h1,h2)
4
GATE CSE 2011
+2
-0.6
We are given a set of n distinct elements and an unlabeled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
A
0
B
1
C
n!
D
(1/n+1) * 2nCn
GATE CSE Subjects
Theory of Computation
Operating Systems
Algorithms
Digital Logic
Database Management System
Data Structures
Computer Networks
Software Engineering
Compiler Design
Web Technologies
General Aptitude
Discrete Mathematics
Programming Languages
Computer Organization
EXAM MAP
Joint Entrance Examination