Consider the original array 17 8 12 4 26. How many comparisons are needed to construct the BST on the original array?

Consider the original array 17 8 12 4 26. How many comparisons are needed to construct the BST on the original array?
A. 5
B. 4
C. 7
D. 10
 
Answer: d
Explanation: Original array is 17 8 12 4 26. The BST built on this array is shown in the figure below.
To built the BST, we travel down the tree until a leaf is reached. Therefore, for every element we compare the element with the internal nodes until we the leaves and then once again compare the element with its parent to decide whether it is right child or left child. So, for given array we need to perform 10 comparisons to build the BST.
 

Tìm kiếm

Back
Top