The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Which of the following trees have height as O(lgn) where number of nodes is n.
A.
R-B Tree
B.
Binary Search Tree
C.
Binary Tree
D.
2-3 Tree
Correct Answer
A. R-B Tree
Explanation The Red-Black Tree has a height of O(lgn) where n is the number of nodes. This is because the Red-Black Tree is a balanced binary search tree that maintains a balance between the left and right subtrees. It achieves this balance by enforcing certain properties, such as every node being either red or black, and the number of black nodes on any path from the root to a leaf being the same. These properties ensure that the tree remains balanced and the height is logarithmic in relation to the number of nodes.
Rate this question:
2.
For a 2 -3 Tree which of the following is true
A.
A 2-3 Tree may have root node with only one child
B.
Maximum number of children of any node is 3
C.
A leave can hight either 2 or 3 in a 2-3 tree
D.
Minimum number of children of any node is 2.
Correct Answer
B. Maximum number of children of any node is 3
Explanation In a 2-3 Tree, the maximum number of children that any node can have is 3. This means that a node can have up to 3 child nodes. This property is what differentiates a 2-3 Tree from other types of trees, where the maximum number of children per node may vary. In a 2-3 Tree, each node can have either 2 or 3 children, and the tree is balanced such that all leaf nodes are at the same height.
Rate this question:
3.
If we first delete a key from an R-B tree and add it back then, how does the structure of resulting R-B tree compare with original R-B tree?
A.
Both trees will be same in all cases
B.
Both will be different in all the cases
C.
Both trees may be same or different depending on the case.
Correct Answer
C. Both trees may be same or different depending on the case.
Explanation When a key is deleted from an R-B tree and then added back, the resulting structure of the R-B tree can be the same as the original tree or different, depending on the case. This is because the structure of an R-B tree is determined by a set of rules that ensure balance and maintain the properties of a red-black tree. Deleting and adding a key can affect the balance of the tree, causing it to be the same or different from the original tree. The outcome will depend on the specific key being deleted and added, as well as the state of the tree before the operations are performed.
Rate this question:
4.
If we first delete a key from 2-3 tree and then add it back then, how does the structure of resulting 2-3 tree compare with original 2-3 tree?
A.
Both trees will be same in all cases
B.
Both will be different in all the cases
C.
Both trees may be same or different depending on the case.
Correct Answer
C. Both trees may be same or different depending on the case.
Explanation When a key is deleted from a 2-3 tree and then added back, the resulting structure of the 2-3 tree may be the same or different from the original tree, depending on the case. This is because the structure of a 2-3 tree is determined by the specific keys that are inserted and deleted. The order in which the keys are inserted or deleted can affect the splitting and merging of nodes, which can result in different tree structures. Therefore, it is possible for the trees to be the same or different depending on the specific keys and operations performed.
Rate this question:
5.
The height of a BST is given as h. Consider the height of the tree as the no. of edges in the longest path from root to the leaf. The maximum no. of nodes possible in the tree is?
A.
2exp(h-1)-1
B.
2exp(h+1)-1
C.
2exp(h)-1
D.
2exp(h+1)-1
Correct Answer
B. 2exp(h+1)-1
Explanation The maximum number of nodes possible in a binary search tree (BST) with height h can be calculated using the formula 2^(h+1) - 1. This formula is derived from the fact that at each level of the BST, the number of nodes doubles. Therefore, at the root level, there is 1 node, at the next level there are 2 nodes, at the next level there are 4 nodes, and so on. So, the total number of nodes in the BST can be calculated by summing up the number of nodes at each level, which is equivalent to 2^(h+1) - 1.
Rate this question:
6.
The tree is an example of
A.
2-3 tree
B.
Binary search Tree
C.
Binomial Heap
D.
Fibonacci Heap
Correct Answer
B. Binary search Tree
Explanation A binary search tree is a type of binary tree where the left child of a node contains a value smaller than the node's value, and the right child contains a value greater than the node's value. This property allows for efficient searching, insertion, and deletion operations. In the given question, the tree is described as an "example," indicating that it serves as a representation or illustration of a binary search tree. Therefore, the correct answer is binary search tree.
Rate this question:
7.
The following are the case of ...................in red black Tree
A.
Insert
B.
Find
C.
Delete
D.
None of these
Correct Answer
C. Delete
Explanation The correct answer is "Delete". In a red-black tree, the delete operation involves removing a node from the tree while maintaining the red-black properties. This operation requires careful restructuring and recoloring of nodes to ensure that the tree remains balanced and satisfies all the red-black tree properties. The insert and find operations also play a role in maintaining the red-black tree properties, but the delete operation specifically deals with removing nodes.
Rate this question:
8.
Suppose a binary tree is constructed with n nodes, such that each node has exactly either zero or two children. The maximum height of the tree will be?
A.
(n+1)/2
B.
(n-1)/2
C.
(n/2)-1
D.
(n+1)/2
Correct Answer
B. (n-1)/2
Explanation The maximum height of a binary tree with n nodes, where each node has either zero or two children, can be found by considering the worst-case scenario. In the worst case, each level of the tree will be completely filled except for the last level, which may be partially filled. The number of nodes in a completely filled binary tree of height h can be calculated using the formula 2^h - 1. In this case, we want to find the maximum height, so we need to find the largest value of h such that 2^h - 1 is less than or equal to n. By solving this equation, we get h = log2(n+1) - 1. Since the height of the tree is one less than h, the maximum height can be expressed as (n-1)/2.
Rate this question:
9.
The run time for traversing all the nodes of a binary search tree with n nodes and printing them in an order is
A.
O(nlg(n))
B.
O(√n)
C.
O(n)
D.
O(lg(n))
Correct Answer
A. O(nlg(n))
Explanation The correct answer is O(nlg(n)) because in order to traverse all the nodes of a binary search tree, we need to visit each node once. The time complexity of visiting a node is O(1). Since there are n nodes in the tree, the total time complexity is O(n). Additionally, printing the nodes in order requires sorting them, which has a time complexity of O(nlg(n)) in the average case. Therefore, the overall time complexity is O(nlg(n)).
Rate this question:
10.
If n numbers are to be sorted in ascending order in O(nlogn) time, which of the following tree can be used
A.
Binary Tree
B.
Binary Search Tree
C.
Max- heap
D.
Min-Heap
Correct Answer
A. Binary Tree
Explanation A binary tree can be used to sort n numbers in ascending order in O(nlogn) time. The binary tree can be constructed by inserting the numbers in a specific order, such as in the order they are given or in a sorted order. Then, by performing an in-order traversal of the binary tree, the numbers can be retrieved in ascending order. This traversal takes O(n) time, and since the height of a binary tree is O(logn), the overall time complexity is O(nlogn).
Rate this question:
11.
The rotation need to be done is
A.
LL
B.
LR
C.
RL
D.
None of these
Correct Answer
A. LL
Explanation The correct answer is "LL" because the given options represent different types of rotations in a binary tree. "LL" refers to a left rotation followed by another left rotation. This means that the left child of the root becomes the new root, and the old root becomes the right child of the new root. This rotation helps to balance the tree and maintain its structure.
Rate this question:
12.
A 2-3 is a tree such that
a) All internal nodes have either 2 or 3 children
b) All path from root to leaves have the same length
The number of internal nodes of a 2-3 tree having 9 leaves could be
A.
4
B.
5
C.
6
D.
7
Correct Answer
A. 4
Explanation In a 2-3 tree, each internal node can have either 2 or 3 children. Since the tree has 9 leaves, there are a total of 9-1=8 internal nodes. However, not all internal nodes need to have 3 children. It is possible to have some internal nodes with 2 children and some with 3 children. Therefore, the number of internal nodes can be less than 8. The minimum number of internal nodes required to have 9 leaves is 4, where there are 3 internal nodes with 2 children each and 1 internal node with 3 children. Therefore, the correct answer is 4.
Rate this question:
13.
Which type of traversal of binary search tree outputs the value in sorted order?
A.
Pre-order
B.
Post-order
C.
In-order
D.
None of these
Correct Answer
C. In-order
Explanation In-order traversal of a binary search tree outputs the values in sorted order because it visits the left subtree first, then the root, and finally the right subtree. This ensures that the values are visited in ascending order, making it an effective way to retrieve the values in sorted order from a binary search tree.
Rate this question:
14.
Suppose we have numbers between 1 and 1000 in a binary search tree and want to search for the number 363. Which of the following sequence could not be the sequence of the node examined?
A binary search tree is generated by inserting in order the following integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of the node in the left sub-tree and right sub-tree of the root, respectively, is
A.
(4,7)
B.
(7,4)
C.
(8,3)
D.
(3,8)
Correct Answer
A. (4,7)
Explanation The correct answer is (4,7) because when inserting the integers in order, the first integer 50 becomes the root of the binary search tree. The integers less than 50 (15, 5, 20, 37, 24) are inserted on the left sub-tree, which results in 4 nodes. The integers greater than 50 (62, 58, 91, 60) are inserted on the right sub-tree, which results in 7 nodes. Therefore, the number of nodes in the left sub-tree and right sub-tree of the root are 4 and 7 respectively.
Rate this question:
Quiz Review Timeline +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.