Skip to content

Commit

Permalink
Fix error in avl_tree del_node function (#11510)
Browse files Browse the repository at this point in the history
* fixed error in del_node function

* Update avl_tree.py

---------

Co-authored-by: Maxim Smolskiy <[email protected]>
  • Loading branch information
Rosepetal2022 and MaximSmolskiy authored Jan 24, 2025
1 parent c666db3 commit 13e4d3e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data_structures/binary_tree/avl_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def del_node(root: MyNode, data: Any) -> MyNode | None:
else:
root.set_right(del_node(right_child, data))

# Re-fetch left_child and right_child references
left_child = root.get_left()
right_child = root.get_right()

if get_height(right_child) - get_height(left_child) == 2:
assert right_child is not None
if get_height(right_child.get_right()) > get_height(right_child.get_left()):
Expand Down

0 comments on commit 13e4d3e

Please sign in to comment.