

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


The CEO of the Computer Sciences Corporation, Dr. Link Queue has just learned that G.M. Adelson-Velsky and E.M. Landis will be visiting the company in two weeks. They want to invest in the company, so Dr. Queue wants to give them a good demo. Thus, he wants you to build an interactive AVL tree tool. In this assignment, you will write an interactive balancing routine for binary trees that utilizes the AVL algorithm.
You will develop an interactive program that will let users insert and delete nodes in a binary search tree (BST) and also run the AVL algorithm. The program should also output the contents of the tree after each operation. Thus, you should provide a menu driven interface that lets users
For operations 2,3, and 5, you should output the tree level, the nodes in that level, and the children each node points to. For example, if I have a binary tree that looks like the following:
22 /
15 30 /
8 18
The output would be
Level 0: Node: 22 โ Left Child Node: 15 โ Right Child Node: 30 Level 1: Node: 15 โ Left Child Node 8 โ Right Child Node: 18 Node: 30 โ Leaf Node Level 2: Node: 8 โ Leaf Node Node: 18 โ Leaf Node
This output makes it very easy for you to draw out the trees on paper.
Approach
Use the following data structure for your BSTs
struct tree_node { int data; struct tree_node *left; struct tree_node *right; int height; };
You should need to write 5 primary functions and some helper functions for this assignment.
struct tree_node * createBST();
struct tree_node* insertBSTNode(struct tree_node *root, int data);
struct tree_node* deleteBSTNode(struct tree_node *root, int data);
int findBalanceFactor (struct tree_node *root);
struct tree_node* balanceTreeAVL(struct tree_node *root);
The helper functions should be used as part of the balanceTreeAVL function to help determine which one of the 4 cases the BST could be in (RR, LL, RL, LR). I would also strongly encourage you to write 4 helper functions that do the rotations for the each case. This will make your code easier to read and debug. Also, make use of the notes for implementing the insert and deletion routines.
Also note, your balancing algorithm only needs to work for balancing factors up to 2 or -2.
You must document your routines. Each function should be commented with what the function does, its input parameters, and what it returns. Comments are very important and will account for 20% of your grade.