Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please pay attention to the prompt: C++ AVL Tree is a Binary Search Tree that allows Balance Factor of each node to be in the

Please pay attention to the prompt:

C++

AVL Tree is a Binary Search Tree that allows Balance Factor of each node to be in the range -1 to 1 (n>=0). Implement a function that takes as input a root node of a Binary Search Tree. This function checks if the BST is a AVL Tree or not.

We have defined the following node C++ Node class for you:

class Node { public: ????????int name; Node* left = NULL; ????????Node* right = NULL; };

Function to code:

bool isAVL(Node* root);

The first input in test cases are nodes of a tree which are inserted in that order. You don't need to implement insert. You have access to the root of the constructed Binary Search Tree. The second line is input n. Return true if the BST is AVL and False if not.

Examples:-

1. Numbers: - 5 2 15 16 9 11 14 ;

Tree:- 5

/ \

2 15

/ \

9 16

\

11

\

14

Balance Factor of tree = left subtree height right subtree height = -3

Therefore, this BST is not an AVL Tree.

Hint: Use a Height function to calculate height of a tree at given node.

Sample Input 1:

5 2 15 16 9 11 14 

Sample Output 1:

false

Sample Input 2:

5 2 15 16 9 11 14 

Sample Output 2:

false

Sample Input 3:

1

Sample Output 3:

true

Sample Input 4:

5 4 8 3 6 7

Sample Output 4:

false

Sample Input 5:

1 2 3 4 5 6 7

Sample Output 5:

false

Sample Input 6:

5 2 15 16 9 11 14 1 3

Sample Output 6:

false

Sample Input 7:

10 5

Sample Output 7:

true

Sample Input 8:

10 5 20

Sample Output 8:

true

Thanks!

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

3. The group answers the questions.

Answered: 1 week ago