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;

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, AVLTree T)

{

if (T == NULL) { /* Create and return a one-node tree */

T = (AVLTree)malloc(sizeof(struct AVLTreeNode));

T->Element = X; T->Height = 0; T->Left = T->Right = NULL;

} /* End creating a one-node tree */

else if (X < T->Element) { /* handle left insertion */

T->Left = Insert(X, T->Left);

if ( ______(1)______ )

if (______(2)______) /* LL Rotation */

T = SingleRotateWithLeft(T);

else /* LR Rotation */

T = DoubleRotateWithLeft(T);

} /* End left */

else if (X > T->Element) { /* handle right insertion */

T->Right = Insert(X, T->Right);

if ( _______(3)_______ )

if ( _______(4)_______ ) /* RR Rotation */

T = SingleRotateWithRight(T);

else /* RL Rotation */

T = DoubleRotateWithRight(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!