Lab 11 Data Structure 16 December
Lab 11 Data Structure 16 December
Search node:
In this task we have write program that would search specific element for this I use if statement
that would compare the root element and the element we want to search if the root element is
equal to the search element then we would return the element again I use if statement that would
check if the key element is greater than root data then it will search in the right of search tree else
it will search in right of search tree and in this way the element is found.
In lab tasks:
In this lab we have to write program that would balance tree if the tree is unbalance we have to
balance it for this we check the node where is it unbalance and which kind of unbalance is it
either right left, left right ,right right and left left. If it is unbalance in right left so first we make
right rotation and then left or if it’s left right unbalance then we first make left then right rotation.
If the tree is unbalance in right right right then we make left rotation and if the tree is unbalance
in left then we make right rotation. For this we write program for each cases and after that we run
it and check where it is unbalance and then we call the cases accordingly.
Left rotation:
Right rotation:
Left left rotation