MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / right_rotation

Function right_rotation

data_structures/binary_tree/avl_tree.py:87–107  ·  view source on GitHub ↗

r""" A B / \ / \ B C Bl A / \ --> / / \ Bl Br UB Br C / UB UB = unbalanced node

(node: MyNode)

Source from the content-addressed store, hash-verified

85
86
87def right_rotation(node: MyNode) -> MyNode:
88 r"""
89 A B
90 / \ / \
91 B C Bl A
92 / \ --> / / \
93 Bl Br UB Br C
94 /
95 UB
96 UB = unbalanced node
97 """
98 print("left rotation node:", node.get_data())
99 ret = node.get_left()
100 assert ret is not None
101 node.set_left(ret.get_right())
102 ret.set_right(node)
103 h1 = my_max(get_height(node.get_right()), get_height(node.get_left())) + 1
104 node.set_height(h1)
105 h2 = my_max(get_height(ret.get_right()), get_height(ret.get_left())) + 1
106 ret.set_height(h2)
107 return ret
108
109
110def left_rotation(node: MyNode) -> MyNode:

Callers 4

lr_rotationFunction · 0.85
rl_rotationFunction · 0.85
insert_nodeFunction · 0.85
del_nodeFunction · 0.85

Calls 8

my_maxFunction · 0.85
get_heightFunction · 0.85
get_dataMethod · 0.80
get_leftMethod · 0.80
set_leftMethod · 0.80
get_rightMethod · 0.80
set_rightMethod · 0.80
set_heightMethod · 0.80

Tested by

no test coverage detected