Sail E0 Webinar
Question
Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?
Options:
A .  just build the tree with the given input
B .  find the median of the set of elements given, make it as root and construct the tree
C .  use trial and error
D .  use dynamic programming to build the tree
Answer: Option B


Sort the given input, find the median element among them, make it as root and construct left and right subtrees with elements lesser and greater than the median element recursively. this ensures the subtrees differ only by height 1.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers