Question: Insert(X, T) inserts X into AVL tree T. Please fill blanks in it. struct AVLTreeNode int Element; struct AVLTreeNode *Left: struct AVLTreeNode *Right; int Height;

 Insert(X, T) inserts X into AVL tree T. Please fill blanks

Insert(X, T) inserts X into AVL tree T. Please fill blanks in it. struct AVLTreeNode int Element; struct AVLTreeNode *Left: struct AVLTreeNode *Right; int Height; }; typedef struct AVLTreeNode *Position, *AVLTree; int Height(AVLTree T) { if (!T) return -1; return T->Height; } int Max(int a, int b) { if (a>b) return a; return b; } AVLTree Insert(ElementType X, AVL Tree T) { if (T == NULL) { /* Create and return a one-node tree */ T = (AVLTree)malloc(sizeof(struct AVL TreeNode)); T->Element = X; T->Height = 0; T->Left = T->Right = NULL; } /* End creating a one-node tree */ else if (X Element) { /* handle left insertion */ T->Left = Insert(X, T->Left); if ( (1) ) if ( (2) .) /* LL Rotation */ T = SingleRotateWith Left(T); else / LR Rotation */ T = DoubleRotate With Left(T); } /* End left */ else if (x > T->Element) { /* handle right insertion */ T->Right = Insert(X, T->Right); if ( (3) ) if (4) ) /* RR Rotation */ T = SingleRotate With Right(T); else / RL Rotation */ T = Double Rotate With Right(T); } /* End right */ /* Else X is in the tree already; we'll do nothing */ T->Height = (5) return T

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!