MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / del_node

Function del_node

data_structures/binary tree/AVLtree.py:152–187  ·  view source on GitHub ↗
(root,data)

Source from the content-addressed store, hash-verified

150 return root.getdata()
151
152def del_node(root,data):
153 if root.getdata() == data:
154 if root.getleft() is not None and root.getright() is not None:
155 temp_data = getLeftMost(root.getright())
156 root.setdata(temp_data)
157 root.setright(del_node(root.getright(),temp_data))
158 elif root.getleft() is not None:
159 root = root.getleft()
160 else:
161 root = root.getright()
162 elif root.getdata() > data:
163 if root.getleft() is None:
164 print("No such data")
165 return root
166 else:
167 root.setleft(del_node(root.getleft(),data))
168 elif root.getdata() < data:
169 if root.getright() is None:
170 return root
171 else:
172 root.setright(del_node(root.getright(),data))
173 if root is None:
174 return root
175 if getheight(root.getright()) - getheight(root.getleft()) == 2:
176 if getheight(root.getright().getright()) > getheight(root.getright().getleft()):
177 root = rightrotation(root)
178 else:
179 root = lrrotation(root)
180 elif getheight(root.getright()) - getheight(root.getleft()) == -2:
181 if getheight(root.getleft().getleft()) > getheight(root.getleft().getright()):
182 root = leftrotation(root)
183 else:
184 root = rlrotation(root)
185 height = my_max(getheight(root.getright()),getheight(root.getleft())) + 1
186 root.setheight(height)
187 return root
188
189class AVLtree:
190 def __init__(self):

Callers 1

del_nodeMethod · 0.85

Calls 14

getLeftMostFunction · 0.85
getheightFunction · 0.85
rightrotationFunction · 0.85
lrrotationFunction · 0.85
leftrotationFunction · 0.85
rlrotationFunction · 0.85
my_maxFunction · 0.85
getdataMethod · 0.80
getleftMethod · 0.80
getrightMethod · 0.80
setdataMethod · 0.80
setrightMethod · 0.80

Tested by

no test coverage detected