Question 1
What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree for a skewed tree ?
O(n) for all
O(Logn) for all
O(Logn) for search and insert, and O(n) for delete
O(Logn) for search, and O(n) for insert and delete
Question 2
In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?
Inorder Successor is always a leaf node
Inorder successor is always either a leaf node or a node with empty left child
Inorder successor may be an ancestor of the node
Inorder successor is always either a leaf node or a node with empty right child
Question 3
We are given a set of n distinct elements and an unlabelled 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? (GATE CS 2011)
0
1
n!
(1/(n+1)).2nCn
Question 4
How many distinct binary search trees can be created out of 4 distinct keys?
4
14
24
42
Question 5
Which of the following traversal outputs the data in sorted order in a BST?
Preorder
Inorder
Postorder
Level order
Question 6
The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)? (GATE CS 2004)
2
3
4
6
Question 7
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
10, 20, 15, 23, 25, 35, 42, 39, 30
15, 10, 25, 23, 20, 42, 35, 39, 30
15, 20, 10, 23, 25, 42, 35, 39, 30
15, 10, 23, 25, 20, 35, 42, 39, 30
Question 8
Consider the following Binary Search Tree
If we randomly search one of the keys present in above BST, what would be the expected number of comparisons?
2.75
2.25
2.57
3.25
Question 9
Question 10
// A BST node
struct 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);
}
}
15 / \\ 10 20 / \\ / \\ 8 12 16 25
There are 41 questions to complete.