Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Consider the following code snippet in C. The function print() receives root of a Binary Search Tree (BST) and a positive integer k as arguments.// A BST nodestruct node {int data;struct node *left, *right;};int count = 0;void print(struct node *root, int k){if (root != NULL && count <= k){print(root->right, k);count++;if (count == k)printf("%d ", root->data);print(root->left, k);}}What is the output of print(root, 3) where root represent root of the following BST. 15 / \ 10 20 / \ / \ 8 12 16 25 (A) 10(B) 16(C) 20(D) 20 10

Answer»
2.

Which of the following traversals is sufficient to construct BST from given traversals1) Inorder2) Preorder3) Postorder(A) Any one of the given three traversals is sufficient(B) Either 2 or 3 is sufficient(C) 2 and 3(D) 1 and 3

Answer»
3.

Consider the same code as given in above question. What does the function print() do in general?The function print() receives root of a Binary Search Tree (BST) and a positive integer k as arguments.// A BST nodestruct node {int data;struct node *left, *right;};int count = 0;void print(struct node *root, int k){if (root != NULL && count <= k){print(root->right, k);count++;if (count == k)printf("%d ", root->data);print(root->left, k);}}(A) Prints the kth smallest element in BST(B) Prints the kth largest element in BST(C) Prints the leftmost node at level k from root(D) Prints the rightmost node at level k from root

Answer»
4.

Consider the following Binary Search Tree 10 / \ 5 20 / / \ 4 15 30 / 11 If we randomly search one of the keys present in above BST, what would be the expected number of comparisons?(A) 2.75(B) 2.25(C) 2.57(D) 3.25

Answer»