Question: 2. [5 pts] Billy wrote the following algorithm whose purpose to test whether or not a given BST is AVL compliant: int getHeight(TreeNode root) {
![2. [5 pts] Billy wrote the following algorithm whose purpose to](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66e06fb9a56d4_69766e06fb925205.jpg)
2. [5 pts] Billy wrote the following algorithm whose purpose to test whether or not a given BST is AVL compliant: int getHeight(TreeNode root) \{ if ( root == null) \{ return 0 ; \} int left_height = getHeight ( root.getLeftchild()) ; int right_height = getHeight ( root.getRightchild()); // assume MAX() returns the maximum value return MAX(left_height, right_height) + 1; \} bool isAvl(TreeNode root) \{ if (root == null) return true; int left_height = getHeight ( root.getLeftchild()); int right_height = getHeight ( root.getRightchild()); //assume ABS() returns the absolute value int difference = ABS (left_height - right_height) ; if(difference > 1 ) \{ return false; \} return true; \} A. [2 pts] What is the runtime complexity of Billy's isAvl() function? Answer. B. [3 pts] Unfortunately, his code doesn't work in every case Explain why with a sample tree
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
