X03_CS506_2023_BinaryTrees_AVLTrees Lab3 Extended10Sep
X03_CS506_2023_BinaryTrees_AVLTrees Lab3 Extended10Sep
Single .c file. Program must be compilable using gcc as we will be likely using linux platform to
evaluate your assignments
You MUST follow the Filename format :
o X03_<Your First name>_<Entrynumber>_23MCS506.c
For e.g. X03_Keshav_2023AIM0000_23MCS506.c exercise
Input outputs that you tried or used for testing your code are recommended to be included in
your program file at end within comments (using /* */) and/or in google form, esp. good I/Os
If you know you code is not working for some cases etc, do mention that clearly in comments
section at the beginning of your code (using /* ….. */) and also in google form
There shall not be any identifiable information within the program. No reference to your name, roll
number etc. shall appear in your code.
Deadline as of now:
09th Sep 2023, 11:59:59 PM
o While submitting, exercise due care and caution to submit the appropriate code (your last
updated program, not your intermediate trial codes) and with proper filename.
o Use only Google form to submit the assignments. Assignment submitted via other means
(Google Classroom / Moodle / Email) won’t be considered for evaluation unless some
prior approval taken for some emergency genuine reasons.
No Plagiarism Please. Please note that we may do plag check now or later even after endsem, and
you will be then (severely) penalized. You must do your own coding and neither take nor provide
codes from/to anyone else.
o Those who complete their works, they are kindly requested to not share their codes in
name of friendship or so. You may get severely penalized for the same and by sharing
codes, you are not really helping them either.
o We sincerely request and hope that you will try your level best and not adopt any unfair
means so that we need NOT go through the painful experience of penalizing you.
================Assignment (To be implement in C using pointers etc) ==================
Tree info would be only accessible only through single pointer i.e. pointer to root node.
*/
T a1 a2 a3 -a2 -a4 a5 .... an Construct BST by adding first a1, then a2, then
a3, removing a2, removing a4, adding a5 ....
//Assume all ai are +ve integers
// Need not insert duplicate value (a5==a3)
// If a4 does not exist, don’t do anything
// Need not print anything
//Sequence of Integers // Any valid 8 bit integer
H a1 a2 a3 -a2 -a4 a5 .... an Construct AVL by adding first a1, then a2, then
a3, removing a2, removing a4, adding a5 ....
//Assume all ai are +ve integers
// Need not insert duplicate value (a5==a3)
// If a4 does not exist, don’t do anything
// Need not print anything
A i j .. k .. Add nodes with values i j k in the tree in this
sequence I j k
//Seq. of integers
//Consider last constructed tree. If no tree, then
consider simple BST that was initially empty). If
any i/j/k is 0 or negative, do nothing.
Some Assumptions/Constraints -
1. Left sub-tree of a node has values less than or equal to node value. Values in right sub-
tree are strictly greater.
2. Elements in the tree are positive. (0 and negative elements not to be there in tree). If you
encounter 0 in query type : T H A or U do nothing.
3. At anytime , there is only one tree in the system. Initially assume BST and its empty i.e.
root=NULL. Whenever you encounter query type T or H, you delete the previous tree and
construct the new tree as per the query. Subsequent queries will then to be performed on
this last constructed tree. When you delete the tree, free the space. Don’t just make
root=NULL.
4. First line of the input would be Z i.e. number of queries and then there would Z lines -
each line indicating a query. For query types T H A and U there would be no output ( your
code works internally in constructing/modifying the tree as per query.). For other queries
there would be single line output
5. Query A and U operates on previously constructed tree. If that was simple BST, then
add/delete nodes preserving BST property. If most recently constructed tree was AVL ,
then add/delete nodes preserving AVL tree property. By default, assume simple BST (This
case would only happen if you observe query type A but you had not observed T or H so
far). Similarly for U as and when applicable.
T 8 3 1 10 14 13 6 5 7 -5 4
or
T 8 3 1 6 4 7 10 14 13
Consider only the left subtree (rooted at 3). Thats AVL tree in itself. It can be
constructed if input query is
H 31 467
or
H13647
Sample Input Output Queries for following BST tree (Tree 2) of three elements 3 ,2 and 1
3
/
2
/
1
====================================================================
A5
A7
A -2
A 3 6 9 -3 7 -11 25 78 96
UPROOT /DELETE THE NODE WILL ONLY DELETE THAT NODE AND NOT
THE TREE UNDERNEATH
Perimeter is 32
So if the query is as follows on above tree, then the output would be 32 as mentioned here
.
Sample Input: Sample Output
Y 32 1 8 7 6 5 3 2
//For Trees 1, 2, and 3 mentioned above, the perimeter is 60, 6 and 6, respectively
Also, note if you have imbalanced AVL after some insertion/delete and there are multiple options applicable e.g. both
left-left case and left-right case applicable, then use the one with least rotations, so use Left-Left compared to Left-Right
(and similarly, use Right-Right rather than Right-Left, in cases when both choices are possible)
https://www.geeksforgeeks.org/diameter-of-a-binary-tree/
https://www.geeksforgeeks.org/maximum-width-of-a-binary-tree/
https://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
6
/ \
4 10
\ \
5 18
/ \
16 27
Boundary Traversal (Clockwise): 6 10 18 27 16 5 4
6
/ \
4 10
/ \ \
2 5 18
/\ / \
1 3 16 27
Boundary Traversal (Clockwise): 6 10 18 27 16 5 3 1 2 4
6
/ \
4 10
/ \ \
2 5 18
/\ /
1 3 16
Boundary Traversal (Clockwise): 6 10 18 16 5 3 1 2 4
6
/ \
4 10
\ \
5 18
/
16
Boundary Traversal (Clockwise): 6 10 18 16 5 4
6
\
10
\
18
/ \
16 20
Boundary Traversal (Clockwise): 6 10 18 20 16
7
/ \
4 10
\ \
6 18
/ /
5 16
Boundary Traversal (Clockwise): 7 10 18 16 5 6 4
https://www.geeksforgeeks.org/maximum-width-of-a-binary-tree/
6
/ \
4 10
/ \ \
3 5 18
/ \
16 27
Max Width = 3 for above mentioned tree
6
/ \
4 10
/ \ \
2 5 18
/\ / \
1 3 16 27
Max Width = 4 for above mentioned tree