Skip to content

Commit

Permalink
"delete_fixup" optimization (keon#873)
Browse files Browse the repository at this point in the history
* "delete_fixup" optimization

* node_min.parent != node -> node_min.parent is not node
  • Loading branch information
izveigor authored Jul 27, 2022
1 parent 8aa29d7 commit e63bc4d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions algorithms/tree/red_black_tree/red_black_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def delete(self, node):
node_color = node_min.color
temp_node = node_min.right
##
if node_min.parent != node:
if node_min.parent is not node:
self.transplant(node_min, node_min.right)
node_min.right = node.right
node_min.right.parent = node_min
Expand All @@ -208,9 +208,9 @@ def delete(self, node):

def delete_fixup(self, node):
# 4 cases
while node != self.root and node.color == 0:
while node is not self.root and node.color == 0:
# node is not root and color is black
if node == node.parent.left:
if node is node.parent.left:
# node is left node
node_brother = node.parent.right

Expand Down

0 comments on commit e63bc4d

Please sign in to comment.