From 6b468e51f0460af95ae852c6fb8a0b3024b25e56 Mon Sep 17 00:00:00 2001 From: maitriupadhyay03-cell Date: Sat, 6 Jun 2026 16:50:31 +0530 Subject: [PATCH 1/3] 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 --- data_structures/binary_tree/treap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/treap.py b/data_structures/binary_tree/treap.py index 3114c6fa1c26..5c67dc8d7ead 100644 --- a/data_structures/binary_tree/treap.py +++ b/data_structures/binary_tree/treap.py @@ -5,7 +5,7 @@ class Node: """ - Treap's node + Treap's nodeh Treap is a binary tree by value and heap by priority """ @@ -41,7 +41,7 @@ def split(root: Node | None, value: int) -> tuple[Node | None, Node | None]: """ if root is None or root.value is None: # None tree is split into 2 Nones return None, None - elif value < root.value: + elif value <= root.value: """ Right tree's root will be current node. Now we split(with the same value) current node's left son From 48e35c87ff23f2692c734700669d48280d91e73c Mon Sep 17 00:00:00 2001 From: maitriupadhyay03-cell Date: Sat, 6 Jun 2026 16:52:00 +0530 Subject: [PATCH 2/3] Fix typo in Treap node docstringfix: remove accidental typo in Node class docstring --- data_structures/binary_tree/treap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/binary_tree/treap.py b/data_structures/binary_tree/treap.py index 5c67dc8d7ead..ca81d5967cb6 100644 --- a/data_structures/binary_tree/treap.py +++ b/data_structures/binary_tree/treap.py @@ -5,7 +5,7 @@ class Node: """ - Treap's nodeh + Treap's node Treap is a binary tree by value and heap by priority """ From e9d86f18e99f57d643859bcc9df6550de0dfc929 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 11 Sep 2026 07:04:58 +0200 Subject: [PATCH 3/3] Fix erase logic in treap.py Adjust split logic to include the value in the right subtree. --- data_structures/binary_tree/treap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/treap.py b/data_structures/binary_tree/treap.py index ca81d5967cb6..ac8b10ffceed 100644 --- a/data_structures/binary_tree/treap.py +++ b/data_structures/binary_tree/treap.py @@ -101,8 +101,8 @@ def erase(root: Node | None, value: int) -> Node | None: Split all nodes with values greater into right. Merge left, right """ - left, right = split(root, value - 1) - _, right = split(right, value) + left, right = split(root, value) + _, right = split(right, value + 1) return merge(left, right)