1. Insert operation on AVL Trees 2. Delete operation on AVL Trees Question 1: For this lab, use your BST code implemented in the previous lab.In this lab, you have to create a height-balanced tree class named “AVL”. Inherit the BST class publicly in your new “AVL” class. You can add “height” variable in your existing TNode struct implementation. Implement the following methods for AVL class: a. A default Constructor which calls the default constructor of base class (BST class). b. Override the insert method of base class (BST class) in your AVL class, so that the AVL tree remains height-balanced after insertion of a new node. c. Override the delete method of base class (BST class) in your AVL class, so that the AVL tree remains height-balanced after deletion of a node. d. A function “height” which returns the height of the tree. int height()const

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

1. Insert operation on AVL Trees
2. Delete operation on AVL Trees
Question 1: For this lab, use your BST code implemented in the previous lab.In this lab, you have
to create a height-balanced tree class named “AVL”. Inherit the BST class publicly in your new
“AVL” class. You can add “height” variable in your existing TNode struct implementation.
Implement the following methods for AVL class:
a. A default Constructor which calls the default constructor of base class (BST class).
b. Override the insert method of base class (BST class) in your AVL class, so that the AVL tree
remains height-balanced after insertion of a new node.
c. Override the delete method of base class (BST class) in your AVL class, so that the AVL tree
remains height-balanced after deletion of a node.
d. A function “height” which returns the height of the tree. int height()const
e. A function “search” which returns a pointer to the value of the node containing the required key
b
Question 2: Now run the following main program.
int main()
{
AVL<int, int> tree;
for (int i = 1; i <= 100; i++)
tree.insert(i, i);
for (int i = -1; i >= -100; i--)
tree.insert(i, i);
for (int i = 150; i > 100; i--)
tree.insert(i, i);
for (int i = -150; i < -100; i++)
tree.insert(i, i);
for (int i = 150; i > 100; i--)
tree.delete(i);

tree.inorderPrintKeys();
cout << endl << endl;
cout <<"Tree Height: "<< tree.height() << endl;
int *val = tree.search(-100);
if (val != nullptr)
{
cout <<"Key= -100 found"<< endl;
}
val = tree.search(-151);
if (val == nullptr)
{
cout <<"Key= -151 not found"<< endl;
}
system("pause");
}
Question 3: Provide the implementation of following functions in your BST class.
1. Add a member function printCommonAncestors which is passed two keys (k1 and k2) as parmeters.
The function then prints the keys of all ancestor nodes that are common between node n1 (containing
key k1) and node n2 (containing key k2).
void printCommonAncestors(K k1, K k2) const;
2. Add a member function getTreeWidth which returns the count of number of nodes of that level that
has the maximum number of nodes. int getTreeWidth() const;
3. Add a member function kthMaxKey which is passed a positive integer (let’s call it K) as a parameter.
The function then finds the kth maximum key from the binary search tree. If the number of nodes is
less than k, then throw an exception. K kthMaxKey(int const key) const;
4. Add a member function is isCompleteBST which returns true if the binary search tree is a complete
binary search tree. A complete binary search tree is a binary search tree in which all levels, except
possibly the last level, are completely filled (they form a perfect binary tree); and the nodes in the last
level are as far left as possible. bool isCompleteBST() const;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY