1.

Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?(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 treeQuestion is taken from AVL Tree topic in portion Binary Trees of Data Structures & Algorithms IThis question was posed to me in an interview.

Answer»

Right option is (b) find the median of the SET of elements GIVEN, MAKE it as root and construct the tree

Easy explanation - 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.



Discussion

No Comment Found

Related InterviewSolutions