Professional Documents
Culture Documents
SUBMITTED BY:
ID NUMBER NAME
L.Ushasree
Ass.professor
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
ACKNOWLEDGEMENTS
It is great pleasure for me to express my gratitude to our honorable President Sri. Koneru
Satyanarayana, for giving the opportunity and platform with facilities in accomplishing the project
based laboratory report.
I express the sincere gratitude to our principal Dr. A. Anand Kumar for his administration
towards our academic growth.
I express sincere gratitude to our Coordinator Dr. D.Haritha for her leadership and constant motivation
provided in successful completion of our academic semester.
I record it as my privilege to deeply thank our pioneer Dr. D.Haritha, HOD-BES for providing
us the efficient faculty and facilities to make our ideas into reality.
I express my sincere thanks to our project supervisor L. USHA SREE for his/her novel
association of ideas, encouragement, appreciation and intellectual zeal which motivated us to venture
this project successfully.
Finally, it is pleased to acknowledge the indebtedness to all those who devoted themselves
directly or indirectly to make this project report success.
1. Abstract 5
2. Introduction 6
7. Implementation 11-13
8. Conclusion 16
4|Page
ABSTRACT
AVL trees are self-balancing binary search trees, crucial in maintaining efficient
search, insertion, and deletion operations. This abstract explores AVL trees, outlining
their structure and fundamental operations.
AVL trees ensure that the height difference between left and right subtrees of any
node (known as the balance factor) remains within [-1, 1], maintaining balance and
guaranteeing logarithmic time complexity for search, insertion, and deletion.
The abstract delves into AVL tree operations, including rotation techniques to
rebalance the tree when necessary. Rotations, such as single and double rotations,
preserve the binary search tree property while restoring balance.
Additionally, the abstract discusses the importance of maintaining AVL tree balance
during insertions and deletions. Insertions and deletions may temporarily violate the
AVL property, requiring rebalancing through rotations to restore balance and
optimize performance.
Furthermore, the abstract touches upon AVL tree variants and enhancements, such as
threaded AVL trees or AVL trees augmented with additional data for specific
applications, emphasizing the adaptability and versatility of AVL trees in various
contexts.
5|Page
INTRODUCTION
AVL trees represent a cornerstone in the realm of data structures, offering a dynamic
and efficient solution for maintaining ordered sets or maps. Introduced by Adelson-
Velsky and Landis in 1962, AVL trees are self-balancing binary search trees designed
to ensure fast search, insertion, and deletion operations by preserving balance
through automatic rebalancing.
The structure of an AVL tree closely resembles that of a binary search tree (BST), with
each node having at most two children: a left child and a right child. However, what
sets AVL trees apart is their ability to maintain balance, defined by the constraint that
the height difference between the left and right subtrees of any node must be within
the range of [-1, 1].
By understanding AVL trees and their operations, we gain valuable insights into the
realm of balanced binary search trees, equipping ourselves with powerful tools for
efficiently managing and manipulating large datasets in diverse computational
applications.
6|Page
AIM
Advantages:-
Disadvantages:-
1. Complexity of Implementation
2. Overhead of Balancing Operations
3. Memory Overhead
4. Difficulty in Real-Time Applications
5. Less Efficient in Highly Dynamic Environments
Future enhancements:-
1. Concurrency Support
2. Cache-conscious Optimizations
3. Adaptive Balancing Strategies
4. Hybrid Data Structures
5. Persistent AVL Trees
6. Adaptive Node Splitting and Merging
7. GPU Acceleration
7|Page
SYSTEM REQUIREMENTS
SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system: Windows Xp or later.
HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM : 16GB
Processor : 64bit
8|Page
DATA FLOW DIAGRAM
9|Page
ALGORITHM
10 | P a g e
IMPLEMENTATION
#include <stdio.h>
#include <stdlib.h>
// function prototyping
struct node *create(int);
struct node *insert(struct node *, int);
struct node *deleteNode(struct node *, int);
struct node *search(struct node *, int);
struct node *rotate_left(struct node *);
struct node *rotate_right(struct node *);
11 | P a g e
int balance_factor(struct node *);
int height(struct node *);
void inorder(struct node *);
void preorder(struct node *);
void postorder(struct node *);
int main()
{
int user_choice, data;
char user_continue = 'y';
struct node *result = NULL;
switch (user_choice)
{
case 1:
printf("\nEnter data: ");
scanf("%d", &data);
root = insert(root, data);
printf("\n%d inserted successfully.", data);
break;
case 2:
printf("\nEnter data to delete: ");
scanf("%d", &data);
root = deleteNode(root, data);
printf("\n%d deleted successfully.", data);
break;
case 3:
printf("\nEnter data to search: ");
scanf("%d", &data);
13 | P a g e
result = search(root, data);
if (result == NULL)
{
printf("\n%d not found!", data);
}
else
{
printf("\n%d found.", data);
}
break;
case 4:
printf("\nInorder traversal: ");
inorder(root);
break;
case 5:
printf("\nPreorder traversal: ");
preorder(root);
break;
case 6:
printf("\nPostorder traversal: ");
14 | P a g e
postorder(root);
break;
case 7:
printf("\n\tProgram Terminated\n");
return 1;
default:
printf("\n\tInvalid Choice\n");
}
return 0;
}
15 | P a g e
// if a memory error has occurred
if (new_node == NULL)
{
printf("\nMemory can't be allocated\n");
return NULL;
}
new_node->data = data;
new_node->left = NULL;
new_node->right = NULL;
return new_node;
}
if (root == NULL)
{
return NULL;
}
if (x > root->data)
{
root->right = deleteNode(root->right, x);
if (balance_factor(root) == 2)
{
if (balance_factor(root->left) >= 0)
{
root = rotate_right(root);
}
else
{
root->left = rotate_left(root->left);
root = rotate_right(root);
}
22 | P a g e
}
}
else if (x < root->data)
{
root->left = deleteNode(root->left, x);
if (balance_factor(root) == -2)
{
if (balance_factor(root->right) <= 0)
{
root = rotate_left(root);
}
else
{
root->right = rotate_right(root->right);
root = rotate_left(root);
}
}
}
else
{
if (root->right != NULL)
{
temp = root->right;
23 | P a g e
while (temp->left != NULL)
temp = temp->left;
root->data = temp->data;
root->right = deleteNode(root->right, temp->data);
if (balance_factor(root) == 2)
{
if (balance_factor(root->left) >= 0)
{
root = rotate_right(root);
}
else
{
root->left = rotate_left(root->left);
root = rotate_right(root);
}
}
}
else
{
return (root->left);
}
}
24 | P a g e
root->ht = height(root);
return (root);
}
if (root->data == key)
{
return root;
}
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
postorder(root->left);
postorder(root->right);
printf("%d ", root->data);
}
27 | P a g e
INTEGRATION AND SYSTEM TESTING
OUTPUTS
Screen Shots:
28 | P a g e
29 | P a g e
30 | P a g e
CONCLUSION:-
In conclusion, AVL trees offer a valuable trade-off. They sacrifice some simplicity
compared to regular binary search trees but gain guaranteed logarithmic time
complexity for search, insertion, and deletion. This makes them ideal for scenarios
where frequent insertions, deletions, and searches are crucial for maintaining
AVL trees require storing an extra value (balance factor) for each node
Implementing AVL tree operations can be more complex than those of binary
31 | P a g e