# Program for AVL Tree in C

Here you will get program for AVL tree in C.

An AVL (Adelson-Velskii and Landis) tree is a height balance tree. These trees are binary search trees in which the height of two siblings are not permitted to differ by more than one. i.e. [Height of the left subtree – Height of right subtree] <= 1.

A C program is given below which performs various operations like creation, insertion, deletion and printing for an AVL tree.

## Program for AVL Tree in C

Output

1)Create:
2)Insert:
3)Delete:
4)Print:
5)Quit:

Enter no. of elements:4

Enter tree data:7 12 4 9

1)Create:
2)Insert:
3)Delete:
4)Print:
5)Quit:

Preorder sequence:
7(Bf=-1)4(Bf=0)12(Bf=1)9(Bf=0)

Inorder sequence:
4(Bf=0)7(Bf=-1)9(Bf=0)12(Bf=1)

1)Create:
2)Insert:
3)Delete:
4)Print:
5)Quit:

Enter a data:7

1)Create:
2)Insert:
3)Delete:
4)Print:
5)Quit:

Preorder sequence:
9(Bf=0)4(Bf=0)12(Bf=0)

Inorder sequence:
4(Bf=0)9(Bf=0)12(Bf=0)

1)Create:
2)Insert:
3)Delete:
4)Print:
5)Quit:

### 19 thoughts on “Program for AVL Tree in C”

1. Hey.. I wan to write an iterative C function that displays the integer values of a given AVL tree ..if somebody can help would be perfect ?

2. Not working properly
if i select create node and enter 5 elements 1 to 5 in order then it is giving the wrong values of BF for each node

3. hello my windows is closing while im using delete and indicating that it has a problm with program

4. Aritra Brahmachari

The height() function is not proper.
if(T->left==NULL)
lh=1; //this programmer uses lh=0 which is wrong
Same goes for T->right==NULL.
Hope this helps.

5. [Error] ‘malloc’ was not declared in this scope
Can someone help me? What should I do with this error?

6. very nice, just one comment: if there is malloc, there also should be free.
The free should be near the end of the Delete function: