From 2d2c6d93b2787b0f63a802328338907236860a21 Mon Sep 17 00:00:00 2001 From: Rachel Date: Tue, 6 Aug 2024 14:49:05 -0700 Subject: [PATCH] fixed error in del_node function --- data_structures/binary_tree/avl_tree.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data_structures/binary_tree/avl_tree.py b/data_structures/binary_tree/avl_tree.py index 9fca72374..f201e20f2 100644 --- a/data_structures/binary_tree/avl_tree.py +++ b/data_structures/binary_tree/avl_tree.py @@ -215,12 +215,15 @@ def del_node(root: MyNode, data: Any) -> MyNode | None: return root else: root.set_left(del_node(left_child, data)) - # root.get_data() < data elif right_child is None: return root 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()):