We create a binary search tree B1 by inserting the numbers 1, 2, 3, 4, 5 into an empty binary search tree. We create another binary search tree B2 by inserting the numbers into an empty binary search tree in the reverse order. What is the difference between the right-most element of B1 and the left-most element of B2?
We create a binary search tree B1 by inserting the numbers 1, 2, 3, 4, 5 into an empty binary search tree. We create another binary search tree B2 by inserting the numbers into an empty binary search tree in the reverse order. What is the difference between the right-most element of B1 and the left-most element of B2? Correct Answer 4
The correct answer is option 3.
Concept:
A binary search tree, also known as an ordered or sorted binary tree is a rooted binary tree data structure in which each internal node stores a key that is higher than all keys in the node's left subtree but less than those in the node's right subtree.
[ alt="F1 Shraddha Harshita 21.02.2022 D1" src="//storage.googleapis.com/tb-img/production/22/02/F1_Shraddha_Harshita_21.02.2022_D1.png" style="width: 271px; height: 154px;">
right-most element of B1= 5
left-most element of B2 = 1
Difference between both B1-B2=5-1=4.
Hence the correct answer is 4.