Consider the following BST: a. How would you rearrange the list in question 1 so
ID: 3734001 • Letter: C
Question
Consider the following BST:
a. How would you rearrange the list in question 1 so that the resulting BST looks like the one above? (This list in question 1 is [71,65,62,60,58,55,48,42,41,40,38,37,29,25,22].)
b. How balanced is this tree?
c. What is the time complexity of searching 22 in this BST?
d. What process done on arrays is similar to item c in both, dynamics, and complexity?
e. Traverse the BST with r+l. What can you tell about the list of values printed?
Explanation / Answer
Solution:
a)
42 37 60 25 40 55 65 22 29 38 41 48 58 62 71
b)
The tree is balanced with the balancing factor of 0 at every node.
c)
4 comparison will be done to search for 22. log n basically since the height of the given tree is 4.
d)
first 22 is compared with 42, since 22 is smaller, we go to the left subtree and compare with 37 again the process grows recursively until 22 (the searched element) is compared with 22 (the node in the tree) and the result is returned.
e)
r+l means right node first, then root, then left.
The traversal would be:
71 65 62 60 58 55 48 42 41 40 38 37 29 25 22
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.