Skip to content

Commit 6b468e5

Browse files
fix: correct treap split() to match docstring for equal values (#7854)
The split() function in treap.py uses `<` comparison but the docstring states that the right subtree should contain values "greater or equal" to the split value. This fix changes `elif value < root.value:` to `elif value <= root.value:` so that equal values go to the right subtree as documented. Fixes #7854
1 parent 6c04620 commit 6b468e5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

data_structures/binary_tree/treap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Node:
77
"""
8-
Treap's node
8+
Treap's nodeh
99
Treap is a binary tree by value and heap by priority
1010
"""
1111

@@ -41,7 +41,7 @@ def split(root: Node | None, value: int) -> tuple[Node | None, Node | None]:
4141
"""
4242
if root is None or root.value is None: # None tree is split into 2 Nones
4343
return None, None
44-
elif value < root.value:
44+
elif value <= root.value:
4545
"""
4646
Right tree's root will be current node.
4747
Now we split(with the same value) current node's left son

0 commit comments

Comments
 (0)