Answered step by step
Verified Expert Solution
Question
1 Approved Answer
add ( self , value: object ) - > None: This method adds a new value to the tree while maintaining its AVL property. Duplicate
addself value: object None:
This method adds a new value to the tree while maintaining its AVL property. Duplicate
values are not allowed. If the value is already in the tree, the method should not change
the tree. It must be implemented with runtime complexity.
Example #:
testcases
#RR
#LL
#RL
#LR
for case in testcases:
tree AVL case
print tree
output:
AVL preorder
AVL preorder
AVL preorder
AVL preorder Example #:
testcases
#
#
# LL LL
# LL LR
# LL RR
range
range
range
range
ABCDE
for case in testcases:
tree AVL case
printINPUT : case
print RESULT : tree
Qutput:
INPUT :
RESULT : AVL preorder
INPUT :
RESULT : AVL preorder
INPUT :
RESULT : AVL preorder
INPUT :
RESULT : AVL preorder
INPUT :
RESULT : AVL preorder
INPUT : range
RESULT : AVL preorder
INPUT : range
RESULT : AVL preorder
INPUT : range
RESULT : AVL preorder
INPUT : range
RESULT : AVL preorder
INPUT : ABCDE
RESULT : AVL preorder B A D C E
INPUT :
RESULT : AVL preorder Example #:
for in range :
case list set randomrandrange for in range
tree AVL
for value in case:
tree.add value
if not tree.isvalidavl:
raise ExceptionPROBLEM WITH ADD OPERATION"
printadd stress test finished'
Output:
add stress test finishedremoveself value: object bool:
This method removes the value from the AVL tree. The method returns True if the value is
removed. Otherwise, it returns False. It must be implemented with runtime
complexity.
NOTE: See 'Specific Instructions' for an explanation of which node replaces the deleted
node.
Example #:
testcases
# no AVL rotation
# no AVL rotation
# no AVL rotation
# no AVL rotation
no AVL rotation
# no AVL rotation
for case, delvalue in testcases:
tree AVL case
printINPUT : tree, "DELETE:", delvalue
tree.remove delvalue
print RESULT : tree
Output:
INPUT : AVL preorder DEL:
RESULT : AVL preorder
INPUT : AVL preorder DEL:
RESULT : AVL preorder
INPUT : AVL preorder DEL:
RESULT : AVL preorder
INPUT : AVL preorder DEL:
RESULT : AVL preorder
INPUT : AVL preorder DEL:
RESULT : AVL preordeExample #:
testcases Example #
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started