Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started