Suppose that we have numbers between 1 and 1000 in a binary search tree, and we want to search for the number 252. Which of the following sequences could not be the sequence of nodes examined?Question 34Select one:814, 91, 800, 129, 801, 134, 252cross out813, 109, 800, 133, 787, 147, 251cross out2, 141, 290, 287, 219, 233, 286, 252cross out2, 288, 276, 108, 155, 271, 270, 167, 252.
Question
Suppose that we have numbers between 1 and 1000 in a binary search tree, and we want to search for the number 252. Which of the following sequences could not be the sequence of nodes examined?Question 34Select one:814, 91, 800, 129, 801, 134, 252cross out813, 109, 800, 133, 787, 147, 251cross out2, 141, 290, 287, 219, 233, 286, 252cross out2, 288, 276, 108, 155, 271, 270, 167, 252.
Solution
The sequence that could not be the sequence of nodes examined when searching for the number 252 in a binary search tree is 2, 288, 276, 108, 155, 271, 270, 167, 252.
Here's why:
In a binary search tree, for each node, all elements in the left subtree are less than the node, and all elements in the right subtree are greater than the node.
Starting from the root (2), the next node (288) is greater than the root, so it should be on the right subtree. However, the next node (276) is less than 288 but greater than 2, so it should be on the left subtree of 288 but the right subtree of 2.
Then, we have 108, which is less than both 288 and 276, so it should be on the left subtree of 276, but it's greater than 2, so it should be on the right subtree of 2.
The sequence continues to violate the binary search tree property, making it impossible to be the sequence of nodes examined when searching for 252.
Similar Questions
Suppose that we have numbers between 1 and 1000 in a binary search tree and we want to search for the number 365. Which of the following sequences could not be the sequence of nodes examined ?
Which of the following sequences cannot occur from a postorder traversal of a binary search tree with the keys 1, 2, 3, 4, 5?2, 1, 4, 5, 32, 1, 5, 3, 41, 2, 3, 5, 41, 3, 4, 5, 2Submit
A binary search tree is generated by inserting following integers: 47, 20, 65, 6, 11, 63, 91, 10, 15, 42, 69, 39The number of nodes in the left subtree and right subtree of the root respectively.A7,5B7, 4C4, 7D5,7
Where is the maximum number in a binary search tree? a) At the root of the tree. b) Anywhere other than root and leaf nodes c) At the leftmost leaf node. d) At the rightmost leaf node
Construct the Binary Search Tree of 5, 10, 4, 2, 16, 7, 1, 20, 15, 3
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.