Answered step by step
Verified Expert Solution
Link Copied!

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) {

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

What is the function of the - rf option in the rm command?

Answered: 1 week ago