0% found this document useful (0 votes)
39 views4 pages

C++ AVL Tree Assignment Guide

This document outlines the instructions for Assignment No. 02 for the CS301 Data Structures course, due on June 23, 2025. Students are required to implement AVL tree operations in C++ without using STL, including insertion, deletion, and in-order traversal, while adhering to specific submission guidelines. The assignment emphasizes the importance of self-balancing binary search trees and includes a problem statement involving the management of employee IDs for XYZ Company.

Uploaded by

uausmanali21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

C++ AVL Tree Assignment Guide

This document outlines the instructions for Assignment No. 02 for the CS301 Data Structures course, due on June 23, 2025. Students are required to implement AVL tree operations in C++ without using STL, including insertion, deletion, and in-order traversal, while adhering to specific submission guidelines. The assignment emphasizes the importance of self-balancing binary search trees and includes a problem statement involving the management of employee IDs for XYZ Company.

Uploaded by

uausmanali21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment No.

02
Total Marks: 20
SEMESTER Spring 2025
Due Date: 23-June, 2025
CS301- Data Structures

Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
1. The assignment is submitted after the due date.
2. The submitted code does NOT compile.
3. The submitted assignment is other than .CPP file.
4. The submitted assignment does NOT open or file is corrupted.
5. The assignment is copied (from other student or ditto copy from handouts or internet).
6. The AVL is not implemented manually and STL is used.

Uploading instructions
For clarity and simplicity, you are required to Upload/Submit only ONE .cpp “ Assignment 2 Template” file
after completing its code.

Note:
1. Use ONLY Dev-C++ IDE.
2. Only add the code were commented (// Write your code here) in given .cpp “ Assignment 2 Template” file.
Don’t change any other code otherwise you will lose your marks.
3. Mention your own student VU id instead of BC123456789 in “ Assignment 2 Template” file as given in the
output screenshot.
4. Only implement these functions insertNode(), deleteNode(), inOrder().

Learning Objectives:

1. To implement AVL tree manually without STL.


2. To perform insertion and deletion while keeping AVL balanced.
3. To perform rotations and update height manually.
4. To appreciate the importance of self-balancing BSTs in improving search, insertion, and deletion.

For any query about the assignment, contact at cs301@[Link]

GOOD LUCK
Problem Statement Marks 20

XYZ Company wants to implement a lightweight AVL Tree to efficiently store and manage their Employee IDs. The
AVL Tree ensures self-balancing to optimize search, insert, and delete operations. Initially, the tree contains the
following Employee IDs: 10, 20, 30, 40 and 50.

To maintain the AVL Tree's balance during updates, your task is to manually implement the AVL Tree operations
using C++, without using any built-in STL libraries.

The system performs the following operations sequentially, as outlined in the provided “Assignment 2
[Link]” file:

1. Extract the Last Digit from Your VU Student ID (VUID):


o Retrieve and display the last numeric digit of your own VUID.
o Example: If your VUID is BC123456789, the extracted digit is 9.
2. Initialize the AVL Tree with Predefined IDs:
o Insert the hardcoded employee IDs: 10, 20, 30, 40 and 50.
o Display the in-order traversal of the AVL Tree after these insertions.
3. Insert Your Extracted Last Digit of your own Student ID into the AVL Tree:
o Insert the digit obtained in Step 1 into the AVL Tree.
o Ensure AVL Tree remains balanced by handling all four rotation cases (Left-Left, Right-Right, Left-
Right, Right-Left).
o Display in-order traversal after insertion.
4. Delete the Extracted Digit from the AVL Tree:
o Remove the digit that was inserted in Step 3.
o Maintain AVL balance after deletion using appropriate rotations.
o Display in-order traversal after deletion.

Your Task to Perform:

1. Implement insertNode() Function:

Which insert a node with your own VUID’s last digit.

Handle all four types of AVL imbalances:


o Left-Left (LL)
o Right-Right (RR)
o Left-Right (LR)
o Right-Left (RL)

2. Implement deleteNode() Function:

Delete the digit inserted above while maintaining AVL balance.

Handle deletion of both leaf and non-leaf nodes.

Handle any imbalance (LL, RR, RL, LR) and ensure appropriate rotation is applied after deletion

3. Implement inOrder() Function:

Implement in-order traversal to display the structure of the AVL Tree. Check sample output screenshot at last
for understanding.

Show traversal results:

o Before insertion
o After insertion
o After deletion

4. Replace Sample VUID with Your Own:

In the code and output messages, replace the example VUID BC123456789 with your actual VUID to
personalize and validate your submission.

Important Notes

 The last digit of your own VUID must be hardcoded in the program. Otherwise you will lose marks.
 Standard Template Library (STL) containers are strictly prohibited.
 All AVL Tree logic (rotations, balancing, etc.) must be implemented manually.
 Ensure your code handles all possible cases of insertion and deletion (e.g., inserting duplicates, deleting root,
leaf, or internal nodes).
 The Assignment 2 [Link] file contains all supporting code, including:
o AVL class structure
o Utility functions: height(), getBalance(), rightRotate(), leftRotate(), minValueNode()
o A main() function with step-by-step instructions

Sample Output Screenshot:

Lectures Covered: This assignment covers Lecture # 20-24.


Deadline: Your assignment must be uploaded/submitted on or before 23-June, 2025.

Common questions

Powered by AI

Challenges one might face while manually implementing functions for AVL Rotation without STL include handling all potential imbalance scenarios correctly, such as Left-Left, Right-Right, Left-Right, and Right-Left cases. Without STL, one must also manually manage node heights, ensuring that every modification during insertions and deletions results in maintaining the AVL properties without inadvertently introducing errors that magnify with additional operations. It requires a comprehensive understanding of tree structures, algorithmic logic, and the implications of every small change on the tree’s balance, making debugging more difficult .

Replacing the sample VUID with your actual VUID is crucial for personalizing and validating your submission. It ensures that the implementation can handle real-world inputs specific to the user and proves that the code is truly customized and not copied, thereby maintaining academic integrity. Additionally, using the actual VUID facilitates testing the correct insertion of the student ID's last digit into the AVL tree .

Rotations contribute to the self-balancing property of AVL Trees by restructuring the nodes to ensure the height difference between the left and right subtrees of any node remains within one. By applying rotations, such as Left-Left (LL), Right-Right (RR), Left-Right (LR), and Right-Left (RL), the tree maintains optimal balance, preventing it from degenerating into a linear structure, thereby ensuring O(log n) time complexity for search, insert, and delete operations. These rotations are necessary after certain insertions and deletions that cause the tree to become unbalanced .

Performing an in-order traversal before and after AVL Tree operations is significant as it allows for visualization of the tree's structure to ensure that it is correctly balanced and retains its binary search tree properties. In-order traversal provides a sorted sequence of the node values, which is especially useful for debugging and verifying the correctness of the implementation after crucial operations like insertion and deletion .

Implementing AVL Trees without using STL libraries requires manual coding of all operations, such as insertion, deletion, and balancing. This involves writing custom functions for rotations and recalculating node heights, which can significantly increase the complexity of the algorithm. It forces the developer to understand deeply how self-balancing mechanisms work, contrary to relying on pre-existing library functions which abstract these details away. This approach demands an accurate handling of different imbalance cases during both insertion and deletion .

Updating heights in AVL Trees can be complex without standard libraries because each node's height must be recalculated and adjusted manually following every insertion and deletion. This process requires keeping track of each node's height and understanding how each rotation affects the node's height within subtrees. The manual implementation demands careful coding to ensure no discrepancies, which becomes increasingly complex as the tree size grows, requiring meticulous tracking and testing to prevent logic errors that could lead to incorrect balance states or operational inefficiencies .

The constraints placed on the submission format and tools include using only Dev-C++ IDE, submitting only a .cpp file, and ensuring that the code compiles without errors. These constraints ensure standardization across submissions, making it easier for evaluators to review and assess the solutions. The requirement to use a specific IDE and file format simplifies the grading process and minimizes complications due to software compatibility issues. Furthermore, these constraints ensure that students adhere to the designated guidelines, concentrating on the coding logic rather than formatting or tooling errors .

Self-balancing Binary Search Trees (BSTs), such as AVL Trees, significantly impact operation efficiency by preventing the tree from becoming skewed, maintaining O(log n) complexity for search, insertion, and deletion operations. This efficiency minimizes the tree’s height, resulting in reduced search times and faster access to data, which is crucial for applications requiring frequent updates and queries. Self-balancing ensures that operational performance remains optimal, regardless of the sequence of input data, unlike unbalanced trees where performance can degrade significantly in the worst-case scenario .

The fundamental operations required to maintain the balance of an AVL Tree include performing rotations such as Left-Left (LL), Right-Right (RR), Left-Right (LR), and Right-Left (RL) on the nodes for balancing after insertion or deletion. These rotations help in adjusting the structure of the tree to ensure that it remains balanced, which minimizes the height and thus ensures efficient search, insert, and delete operations .

Manually handling both leaf and non-leaf node deletions in an AVL Tree is important to ensure the tree remains balanced and adheres to AVL properties. Deleting different types of nodes can disrupt the tree's structure differently, requiring specific corrective actions such as balance adjustments and rotations. Proper handling of these deletions prevents imbalances that can significantly degrade the tree's performance, ensuring all operations maintain their expected time complexities. It also avoids potential logic errors that can arise from assuming simpler cases in an automatic or library-based implementation .

You might also like