From 60a8458f3455c12fac95ffdbaa11c41e0ab4a233 Mon Sep 17 00:00:00 2001 From: Aiman Hasan Date: Mon, 30 Mar 2020 18:00:37 +0500 Subject: [PATCH 01/33] Implemented CartesianTreeNode --- pydatastructs/utils/misc_util.py | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pydatastructs/utils/misc_util.py b/pydatastructs/utils/misc_util.py index 88b7a90e7..bfdb1074a 100644 --- a/pydatastructs/utils/misc_util.py +++ b/pydatastructs/utils/misc_util.py @@ -6,7 +6,8 @@ 'AdjacencyListGraphNode', 'AdjacencyMatrixGraphNode', 'GraphEdge', - 'Set' + 'Set', + 'CartesianTreeNode' ] _check_type = lambda a, t: isinstance(a, t) @@ -52,6 +53,36 @@ def __str__(self): """ return str((self.left, self.key, self.data, self.right)) +class CartesianTreeNode(TreeNode): + """ + Represents node in cartesian trees. + + Parameters + ========== + + data + Any valid data to be stored in the node. + key + Required for comparison operations. + priority: int + An integer value for heap property. + + """ + __slots__ = ['key', 'data', 'priotity'] + + def __new__(cls, key, priority, data=None): + obj = TreeNode.__new__(cls, key, data) + obj.priority = priority + return obj + + def __str__(self): + """ + Used for printing. + """ + return str((self.left, self.key, self.priority, self.data, self.right)) + + + class BinomialTreeNode(TreeNode): """ Represents node in binomial trees. From b1daa60b63a5ac37aa3133d3deb0148eaa381920 Mon Sep 17 00:00:00 2001 From: Aiman Hasan Date: Mon, 30 Mar 2020 18:01:27 +0500 Subject: [PATCH 02/33] Added CartesianTreeNode in __init__ --- pydatastructs/utils/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydatastructs/utils/__init__.py b/pydatastructs/utils/__init__.py index 6c68c2f18..5ed15e991 100644 --- a/pydatastructs/utils/__init__.py +++ b/pydatastructs/utils/__init__.py @@ -9,6 +9,7 @@ AdjacencyListGraphNode, AdjacencyMatrixGraphNode, GraphEdge, - Set + Set, + CartesianTreeNode ) __all__.extend(misc_util.__all__) From 16d8076bd5701152cb7ff2a16927334a62c31e9f Mon Sep 17 00:00:00 2001 From: Aiman Hasan Date: Mon, 30 Mar 2020 18:03:06 +0500 Subject: [PATCH 03/33] Implemented CartesianTree and Treap --- pydatastructs/trees/binary_trees.py | 196 +++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index e197d63ba..7ea9f2f6c 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -1,16 +1,20 @@ from pydatastructs.utils import TreeNode +from pydatastructs.utils import CartesianTreeNode from pydatastructs.miscellaneous_data_structures import Stack from pydatastructs.linear_data_structures import ( OneDimensionalArray, DynamicOneDimensionalArray) from pydatastructs.linear_data_structures.arrays import ArrayForTrees from collections import deque as Queue +import random __all__ = [ 'AVLTree', 'BinaryTree', 'BinarySearchTree', 'BinaryTreeTraversal', - 'BinaryIndexedTree' + 'BinaryIndexedTree', + 'CartesianTree', + 'Treap' ] class BinaryTree(object): @@ -623,7 +627,197 @@ def _left_rotate(self, j, k): kp = self.tree[k].parent if kp is None: self.root_idx = k + +class CartesianTree(SelfBalancingBinaryTree): + """ + Represents cartesian trees. + + Examples + ======== + + >>> from pydatastructs.trees import CartesianTree as CT + >>> c = CT() + >>> c.insert(1, 1, 4) + >>> c.insert(2, 2, 3) + >>> child = b.tree[b.root_idx].right + >>> c.tree[child].data + 1 + >>> c.search(1) + 0 + >>> c.search(-1) is None + True + >>> c.delete(1) is True + True + >>> c.search(1) is None + True + >>> c.delete(2) is True + True + >>> c.search(2) is None + True + + References + ========== + + .. [1] https://www.cs.princeton.edu/courses/archive/spr09/cos423/Lectures/geo-st.pdf + + See Also + ======== + + pydatastructs.trees.binary_tree.SelfBalancingBinaryTree + """ + + def _left_rotate(self, j, k): + y = self.tree[k].left + if y is not None: + self.tree[y].parent = j + self.tree[j].right = y + self.tree[k].parent = self.tree[j].parent + if self.tree[k].parent is not None: + if self.tree[self.tree[k].parent].left == j: + self.tree[self.tree[k].parent].left = k + else: + self.tree[self.tree[k].parent].right = k + + self.tree[j].parent = k + self.tree[k].left = j + kp = self.tree[k].parent + if kp is None: + self.root_idx = k + + def _right_rotate(self, j, k): + y = self.tree[k].right + if y is not None: + self.tree[y].parent = j + self.tree[j].left = y + self.tree[k].parent = self.tree[j].parent + if self.tree[k].parent is not None: + if self.tree[self.tree[k].parent].left == j: + self.tree[self.tree[k].parent].left = k + else: + self.tree[self.tree[k].parent].right = k + self.tree[j].parent = k + self.tree[k].right = j + kp = self.tree[k].parent + if kp is None: + self.root_idx = k + + def _bubble_up(self, node_idx): + node = self.tree[node_idx] + parent_idx = self.tree[node_idx].parent + parent = self.tree[parent_idx] + while (node.parent != None) and (parent.priority > node.priority): + if parent.right == node_idx: + self._left_rotate(parent_idx, node_idx) + + else: + self._right_rotate(parent_idx, node_idx) + + node = self.tree[node_idx] + parent_idx = self.tree[node_idx].parent + if parent_idx != None: + parent = self.tree[parent_idx] + if node.parent == None: + self.tree[node_idx].is_root = True + + def _trickle_down(self, node_idx): + node = self.tree[node_idx] + parent_idx = node.parent + while node.left != None or node.right != None: + + if node.left == None: + self._left_rotate(node_idx, self.tree[node_idx].right) + elif node.right == None: + self._right_rotate(node_idx, self.tree[node_idx].left) + elif self.tree[node.left].priority < self.tree[node.right].priority: + self._right_rotate(node_idx, self.tree[node_idx].left) + else: + self._left_rotate(node_idx, self.tree[node_idx].right) + + node = self.tree[node_idx] + parent_idx = node.parent + + + def insert(self, key, data, priority): + super(CartesianTree, self).insert(key, data) + node_idx = super(CartesianTree, self).search(key) + node = self.tree[node_idx] + new_node = CartesianTreeNode(key, priority, data) + new_node.parent = node.parent + new_node.left = node.left + new_node.right = node.right + self.tree[node_idx] = new_node + if node.is_root: + self.tree[node_idx].is_root = True + else: + self._bubble_up(node_idx) + + def delete(self, key, **kwargs): + node_idx = super(CartesianTree, self).search(key) + if node_idx != None: + self._trickle_down(node_idx) + return super(CartesianTree, self).delete(key, balancing_info = True) + return None + + def __str__(self): + to_be_printed = ['' for i in range(self.tree._last_pos_filled + 1)] + for i in range(self.tree._last_pos_filled + 1): + if self.tree[i] is not None: + node = self.tree[i] + to_be_printed[i] = (node.left, node.key, node.priority, node.data, node.right) + return str(to_be_printed) + + + +class Treap(CartesianTree): + + """ + Represents treaps. + + Examples + ======== + + >>> from pydatastructs.trees import Treap as T + >>> t = T() + >>> t.insert(1, 1) + >>> t.insert(2, 2) + >>> child = t.tree[b.root_idx].right + >>> t.tree[child].data + 1 + >>> t.search(1) + 0 + >>> t.search(-1) is None + True + >>> t.delete(1) is True + True + >>> t.search(1) is None + True + >>> t.delete(2) is True + True + >>> t.search(2) is None + True + + References + ========== + + .. [1] https://en.wikipedia.org/wiki/Binary_search_tree + + See Also + ======== + + pydatastructs.trees.binary_tree.SelfBalancingBinaryTree + """ + + priorities = set() + + def insert(self, key, data): + priority = random.random() + while priority in self.priorities: + priority = random.random() + self.priorities.add(priority) + super(Treap, self).insert(key, data, priority) + + class AVLTree(SelfBalancingBinaryTree): """ Represents AVL trees. From d9b69b7a32597709dcf4cdfbb12fa7daaf000fca Mon Sep 17 00:00:00 2001 From: Aiman Hasan Date: Mon, 30 Mar 2020 18:04:42 +0500 Subject: [PATCH 04/33] Added CartesianTree and Treap in __init__ --- pydatastructs/trees/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pydatastructs/trees/__init__.py b/pydatastructs/trees/__init__.py index 42f919c35..9b71dfa39 100644 --- a/pydatastructs/trees/__init__.py +++ b/pydatastructs/trees/__init__.py @@ -12,7 +12,9 @@ BinarySearchTree, BinaryTreeTraversal, AVLTree, - BinaryIndexedTree + BinaryIndexedTree, + CartesianTree, + Treap ) __all__.extend(binary_trees.__all__) From 596b4a3aa8ad4f789abe9e8ba49554da497afed5 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:38:27 +0500 Subject: [PATCH 05/33] Added suggestions Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/binary_trees.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 7ea9f2f6c..55e6b2aba 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -770,7 +770,6 @@ def __str__(self): class Treap(CartesianTree): - """ Represents treaps. From 695d1e313f24f5c7f9cc2fd9b17cd1f5155053f2 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:41:34 +0500 Subject: [PATCH 06/33] Updated reference as in suggestion Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/binary_trees.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 55e6b2aba..a5e7be9ef 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -799,7 +799,7 @@ class Treap(CartesianTree): References ========== - .. [1] https://en.wikipedia.org/wiki/Binary_search_tree + .. [1] https://en.wikipedia.org/wiki/Treap See Also ======== From 34520f16e60f88852f7aa428d65aaeb185ce5fa2 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:42:30 +0500 Subject: [PATCH 07/33] Removed See Also on line 805 as suggested Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/binary_trees.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index a5e7be9ef..6b31eadfd 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -801,10 +801,6 @@ class Treap(CartesianTree): .. [1] https://en.wikipedia.org/wiki/Treap - See Also - ======== - - pydatastructs.trees.binary_tree.SelfBalancingBinaryTree """ priorities = set() From bb96d0db58a11bc419a73a8098918a89b14a5ef7 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:43:04 +0500 Subject: [PATCH 08/33] Removed line as suggested Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/binary_trees.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 6b31eadfd..708aee319 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -757,7 +757,6 @@ def delete(self, key, **kwargs): if node_idx != None: self._trickle_down(node_idx) return super(CartesianTree, self).delete(key, balancing_info = True) - return None def __str__(self): to_be_printed = ['' for i in range(self.tree._last_pos_filled + 1)] From 29a81c5fc69551447b1cbc4fec77f3f6960ff44b Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:47:41 +0500 Subject: [PATCH 09/33] Removed rotations from `CartesianTree` Rotations fixed in Issue #234 with PR #238 --- pydatastructs/trees/binary_trees.py | 35 ----------------------------- 1 file changed, 35 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 708aee319..6639f92a1 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -667,41 +667,6 @@ class CartesianTree(SelfBalancingBinaryTree): pydatastructs.trees.binary_tree.SelfBalancingBinaryTree """ - def _left_rotate(self, j, k): - y = self.tree[k].left - if y is not None: - self.tree[y].parent = j - self.tree[j].right = y - self.tree[k].parent = self.tree[j].parent - if self.tree[k].parent is not None: - if self.tree[self.tree[k].parent].left == j: - self.tree[self.tree[k].parent].left = k - else: - self.tree[self.tree[k].parent].right = k - - self.tree[j].parent = k - self.tree[k].left = j - kp = self.tree[k].parent - if kp is None: - self.root_idx = k - - def _right_rotate(self, j, k): - y = self.tree[k].right - if y is not None: - self.tree[y].parent = j - self.tree[j].left = y - self.tree[k].parent = self.tree[j].parent - if self.tree[k].parent is not None: - if self.tree[self.tree[k].parent].left == j: - self.tree[self.tree[k].parent].left = k - else: - self.tree[self.tree[k].parent].right = k - self.tree[j].parent = k - self.tree[k].right = j - kp = self.tree[k].parent - if kp is None: - self.root_idx = k - def _bubble_up(self, node_idx): node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent From 91522f8eee4e2906d8aa2f7190ea565f81808ed9 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 30 Mar 2020 20:49:32 +0500 Subject: [PATCH 10/33] Updated as suggested in importing the nodes --- pydatastructs/trees/binary_trees.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 6639f92a1..0dda72660 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -1,5 +1,4 @@ -from pydatastructs.utils import TreeNode -from pydatastructs.utils import CartesianTreeNode +from pydatastructs.utils import TreeNode, CartesianTreeNode from pydatastructs.miscellaneous_data_structures import Stack from pydatastructs.linear_data_structures import ( OneDimensionalArray, DynamicOneDimensionalArray) From 3d0b1cdda790c04f78d45ec4e69aefc62a30c48c Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Thu, 16 Apr 2020 23:35:30 +0500 Subject: [PATCH 11/33] Tests added --- .../trees/tests/test_binary_trees.py | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index d14929dd4..b41a45ad8 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -1,6 +1,6 @@ from pydatastructs.trees.binary_trees import ( BinarySearchTree, BinaryTreeTraversal, AVLTree, - ArrayForTrees, BinaryIndexedTree) + ArrayForTrees, BinaryIndexedTree, CartesianTree, Treap) from pydatastructs.utils.raises_util import raises from pydatastructs.utils.misc_util import TreeNode from copy import deepcopy @@ -305,7 +305,7 @@ def test_select_rank(expected_output): test_select_rank([2]) a5.delete(2) test_select_rank([]) - + def test_BinaryIndexedTree(): FT = BinaryIndexedTree @@ -319,3 +319,54 @@ def test_BinaryIndexedTree(): assert t.get_sum(0, 2) == 105 assert t.get_sum(0, 4) == 114 assert t.get_sum(1, 9) == 54 + +def test_CartesianTree(): + tree = CartesianTree() + tree.insert(3, 3, 1) + tree.insert(1, 1, 6) + tree.insert(0, 0, 9) + tree.insert(5, 5, 11) + tree.insert(4, 4, 14) + tree.insert(9, 9, 17) + tree.insert(7, 7, 22) + tree.insert(6, 6, 42) + tree.insert(8, 8, 49) + tree.insert(2, 2, 99) + assert str(tree) == \ + ("[(1, 3, 1, 3, 3), (2, 1, 6, 1, 9), " + "(None, 0, 9, 0, None), (4, 5, 11, 5, 5), " + "(None, 4, 14, 4, None), (6, 9, 17, 9, None), " + "(7, 7, 22, 7, 8), (None, 6, 42, 6, None), " + "(None, 8, 49, 8, None), (None, 2, 99, 2, None)]") + tree.insert(1.5, 1.5, 4) + assert str(tree) == \ + ("[(10, 3, 1, 3, 3), (2, 1, 6, 1, None), " + "(None, 0, 9, 0, None), (4, 5, 11, 5, 5), " + "(None, 4, 14, 4, None), (6, 9, 17, 9, None), " + "(7, 7, 22, 7, 8), (None, 6, 42, 6, None), " + "(None, 8, 49, 8, None), (None, 2, 99, 2, None), " + "(1, 1.5, 4, 1.5, 9)]") + k = tree.search(1.5) + assert tree.tree[tree.tree[k].parent].key == 3 + tree.delete(1.5) + tree.tree[tree.tree[tree.root_idx].left].key == 1 + tree.delete(8) + assert tree.search(8) == None + tree.delete(7) + assert tree.search(7) == None + tree.delete(3) + assert tree.search(3) == None + assert tree.delete(18) == None + +def test_Treap(): + tree = Treap() + tree.insert(7,7) + tree.insert(2,2) + tree.insert(3,3) + tree.insert(4,4) + tree.insert(5,5) + assert isinstance(tree.tree[0].priority, float) + tree.delete(1) + assert tree.search(1) == None + assert tree.search(2) == 1 + assert tree.delete(1) == None From e6fafe6c376a1fd5b1b5677ee6d54a96b5518326 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:00:45 +0500 Subject: [PATCH 12/33] Removed trailing white spaces --- pydatastructs/trees/binary_trees.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 0117ffd1e..a91e7cbc5 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -635,9 +635,8 @@ def _left_rotate(self, j, k): kp = self.tree[k].parent if kp is None: self.root_idx = k - -class CartesianTree(SelfBalancingBinaryTree): +class CartesianTree(SelfBalancingBinaryTree): """ Represents cartesian trees. @@ -674,30 +673,26 @@ class CartesianTree(SelfBalancingBinaryTree): pydatastructs.trees.binary_tree.SelfBalancingBinaryTree """ - def _bubble_up(self, node_idx): node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent parent = self.tree[parent_idx] while (node.parent != None) and (parent.priority > node.priority): if parent.right == node_idx: - self._left_rotate(parent_idx, node_idx) - + self._left_rotate(parent_idx, node_idx) else: self._right_rotate(parent_idx, node_idx) - - node = self.tree[node_idx] + node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent if parent_idx != None: parent = self.tree[parent_idx] if node.parent == None: self.tree[node_idx].is_root = True - + def _trickle_down(self, node_idx): node = self.tree[node_idx] parent_idx = node.parent while node.left != None or node.right != None: - if node.left == None: self._left_rotate(node_idx, self.tree[node_idx].right) elif node.right == None: @@ -706,11 +701,9 @@ def _trickle_down(self, node_idx): self._right_rotate(node_idx, self.tree[node_idx].left) else: self._left_rotate(node_idx, self.tree[node_idx].right) - node = self.tree[node_idx] parent_idx = node.parent - - + def insert(self, key, data, priority): super(CartesianTree, self).insert(key, data) node_idx = super(CartesianTree, self).search(key) @@ -724,7 +717,7 @@ def insert(self, key, data, priority): self.tree[node_idx].is_root = True else: self._bubble_up(node_idx) - + def delete(self, key, **kwargs): node_idx = super(CartesianTree, self).search(key) if node_idx != None: @@ -739,8 +732,6 @@ def __str__(self): to_be_printed[i] = (node.left, node.key, node.priority, node.data, node.right) return str(to_be_printed) - - class Treap(CartesianTree): """ Represents treaps. @@ -774,17 +765,14 @@ class Treap(CartesianTree): .. [1] https://en.wikipedia.org/wiki/Treap """ - priorities = set() - def insert(self, key, data): priority = random.random() while priority in self.priorities: priority = random.random() self.priorities.add(priority) super(Treap, self).insert(key, data, priority) - - + class AVLTree(SelfBalancingBinaryTree): """ Represents AVL trees. From 686cdb307582b229cb6db82dabbda95671feb1e0 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:09:59 +0500 Subject: [PATCH 13/33] Removed trailing white spaces from test --- pydatastructs/trees/tests/test_binary_trees.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index dd15c0b05..8e1dd9717 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -319,7 +319,7 @@ def test_BinaryIndexedTree(): assert t.get_sum(0, 2) == 105 assert t.get_sum(0, 4) == 114 assert t.get_sum(1, 9) == 54 - + def test_CartesianTree(): tree = CartesianTree() tree.insert(3, 3, 1) @@ -357,7 +357,7 @@ def test_CartesianTree(): tree.delete(3) assert tree.search(3) == None assert tree.delete(18) == None - + def test_Treap(): tree = Treap() tree.insert(7,7) @@ -370,7 +370,7 @@ def test_Treap(): assert tree.search(1) == None assert tree.search(2) == 1 assert tree.delete(1) == None - + def test_issue_234(): """ https://github.com/codezonediitj/pydatastructs/issues/234 @@ -432,4 +432,4 @@ def test_SplayTree(): s = t.split(200) assert str(s) == ("[(1, 2000, 2000, None), (None, 1000, 1000, None)]") assert str(t) == ("[(None, 100, 100, None), '', (6, 200, 200, None), (4, 50, 50, None), " - "(5, 30, 30, None), (None, 20, 20, None), (3, 55, 55, 0), '', '', '']") \ No newline at end of file + "(5, 30, 30, None), (None, 20, 20, None), (3, 55, 55, 0), '', '', '']") From 3e0fa6a5c2b349f38518b3046ecfb1e6e59569b6 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:22:45 +0500 Subject: [PATCH 14/33] Removed whitespace on line 308 --- pydatastructs/trees/tests/test_binary_trees.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index 8e1dd9717..14bfaf687 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -305,7 +305,7 @@ def test_select_rank(expected_output): test_select_rank([2]) a5.delete(2) test_select_rank([]) - + def test_BinaryIndexedTree(): FT = BinaryIndexedTree From 8db58484d3090b2c1e666db0b921e0affec5a2a9 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:33:33 +0500 Subject: [PATCH 15/33] Replaced comparison by values with comparison by references in binary_trees.py --- pydatastructs/trees/binary_trees.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index a91e7cbc5..e73f2774d 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -677,25 +677,25 @@ def _bubble_up(self, node_idx): node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent parent = self.tree[parent_idx] - while (node.parent != None) and (parent.priority > node.priority): + while (node.parent is not None) and (parent.priority > node.priority): if parent.right == node_idx: self._left_rotate(parent_idx, node_idx) else: self._right_rotate(parent_idx, node_idx) node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent - if parent_idx != None: + if parent_idx is not None: parent = self.tree[parent_idx] - if node.parent == None: + if node.parent is None: self.tree[node_idx].is_root = True def _trickle_down(self, node_idx): node = self.tree[node_idx] parent_idx = node.parent - while node.left != None or node.right != None: - if node.left == None: + while node.left is not None or node.right is not None: + if node.left is None: self._left_rotate(node_idx, self.tree[node_idx].right) - elif node.right == None: + elif node.right is None: self._right_rotate(node_idx, self.tree[node_idx].left) elif self.tree[node.left].priority < self.tree[node.right].priority: self._right_rotate(node_idx, self.tree[node_idx].left) @@ -720,7 +720,7 @@ def insert(self, key, data, priority): def delete(self, key, **kwargs): node_idx = super(CartesianTree, self).search(key) - if node_idx != None: + if node_idx is not None: self._trickle_down(node_idx) return super(CartesianTree, self).delete(key, balancing_info = True) From 99c8c4126ad623c51a40e0c5680c4f4b774459ae Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:35:16 +0500 Subject: [PATCH 16/33] Removed reference by values in test_binary_trees.py --- pydatastructs/trees/tests/test_binary_trees.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index 14bfaf687..a7b1e1192 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -351,12 +351,12 @@ def test_CartesianTree(): tree.delete(1.5) tree.tree[tree.tree[tree.root_idx].left].key == 1 tree.delete(8) - assert tree.search(8) == None + assert tree.search(8) is None tree.delete(7) - assert tree.search(7) == None + assert tree.search(7) is None tree.delete(3) - assert tree.search(3) == None - assert tree.delete(18) == None + assert tree.search(3) is None + assert tree.delete(18) is None def test_Treap(): tree = Treap() @@ -367,9 +367,9 @@ def test_Treap(): tree.insert(5,5) assert isinstance(tree.tree[0].priority, float) tree.delete(1) - assert tree.search(1) == None + assert tree.search(1) is None assert tree.search(2) == 1 - assert tree.delete(1) == None + assert tree.delete(1) is None def test_issue_234(): """ From b62df259cbe1359e17dfe76660a9fd0061a4b397 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:56:43 +0500 Subject: [PATCH 17/33] Updated delete of `CartesianTree` --- pydatastructs/trees/binary_trees.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index e73f2774d..c335e944c 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -719,10 +719,11 @@ def insert(self, key, data, priority): self._bubble_up(node_idx) def delete(self, key, **kwargs): + balancing_info = kwargs.get('balancing_info', False) node_idx = super(CartesianTree, self).search(key) if node_idx is not None: self._trickle_down(node_idx) - return super(CartesianTree, self).delete(key, balancing_info = True) + return super(CartesianTree, self).delete(key, balancing_info = balancing_info) def __str__(self): to_be_printed = ['' for i in range(self.tree._last_pos_filled + 1)] From 5b362c05f347c56acfafd1c2bcd561ebfe1e1e13 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Sun, 19 Apr 2020 23:59:41 +0500 Subject: [PATCH 18/33] Updated docs --- pydatastructs/trees/binary_trees.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index c335e944c..4ba521a52 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -647,7 +647,7 @@ class CartesianTree(SelfBalancingBinaryTree): >>> c = CT() >>> c.insert(1, 1, 4) >>> c.insert(2, 2, 3) - >>> child = b.tree[b.root_idx].right + >>> child = c.tree[c.root_idx].left >>> c.tree[child].data 1 >>> c.search(1) @@ -744,9 +744,6 @@ class Treap(CartesianTree): >>> t = T() >>> t.insert(1, 1) >>> t.insert(2, 2) - >>> child = t.tree[b.root_idx].right - >>> t.tree[child].data - 1 >>> t.search(1) 0 >>> t.search(-1) is None From 4e8a06f2c2cdd123d7006ddb4ace3e7ed4b9e1a5 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 20 Apr 2020 00:11:11 +0500 Subject: [PATCH 19/33] Removed trailing spaces in misc_util.py --- pydatastructs/utils/misc_util.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pydatastructs/utils/misc_util.py b/pydatastructs/utils/misc_util.py index bfdb1074a..faaf81b02 100644 --- a/pydatastructs/utils/misc_util.py +++ b/pydatastructs/utils/misc_util.py @@ -66,10 +66,9 @@ class CartesianTreeNode(TreeNode): Required for comparison operations. priority: int An integer value for heap property. - - """ - __slots__ = ['key', 'data', 'priotity'] + """ + __slots__ = ['key', 'data', 'priority'] def __new__(cls, key, priority, data=None): obj = TreeNode.__new__(cls, key, data) obj.priority = priority @@ -81,8 +80,6 @@ def __str__(self): """ return str((self.left, self.key, self.priority, self.data, self.right)) - - class BinomialTreeNode(TreeNode): """ Represents node in binomial trees. From d9a8a79fab4c6ae1e11e7cea80262d4fe794abf5 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 20 Apr 2020 00:20:47 +0500 Subject: [PATCH 20/33] Added CartesianTreeNode test --- pydatastructs/utils/tests/test_misc_util.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pydatastructs/utils/tests/test_misc_util.py b/pydatastructs/utils/tests/test_misc_util.py index 6cfd18b4c..324635b21 100644 --- a/pydatastructs/utils/tests/test_misc_util.py +++ b/pydatastructs/utils/tests/test_misc_util.py @@ -38,3 +38,7 @@ def test_MAryTreeNode(): m.add_children(*[i for i in range(2,10)]) assert str(m) == "(1, 1)" assert str(m.children) == "['2', '3', '4', '5', '6', '7', '8', '9']" + +def test_CartesianTreeNode(): + c = CartesianTreeNode(1,1,1) + assert str(c) == "(None, 1, 1, 1, None)" From 5b2a671960ebc154097a9cc026857e2d8c04c05c Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Mon, 20 Apr 2020 00:27:23 +0500 Subject: [PATCH 21/33] Imported CartesianTreeNode in test_misc_util.py --- pydatastructs/utils/tests/test_misc_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/utils/tests/test_misc_util.py b/pydatastructs/utils/tests/test_misc_util.py index 324635b21..42fe876d9 100644 --- a/pydatastructs/utils/tests/test_misc_util.py +++ b/pydatastructs/utils/tests/test_misc_util.py @@ -1,5 +1,5 @@ from pydatastructs.utils import (AdjacencyListGraphNode, AdjacencyMatrixGraphNode, - GraphEdge, BinomialTreeNode, MAryTreeNode) + GraphEdge, BinomialTreeNode, MAryTreeNode, CartesianTreeNode) from pydatastructs.utils.raises_util import raises def test_AdjacencyListGraphNode(): From d97bd8c02c143dfd2633d91c00c1997a325011df Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:01:43 +0500 Subject: [PATCH 22/33] As suggested #1 Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/tests/test_binary_trees.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index a7b1e1192..4d9874d58 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -4,6 +4,7 @@ from pydatastructs.utils.raises_util import raises from pydatastructs.utils.misc_util import TreeNode from copy import deepcopy +import random def test_BinarySearchTree(): BST = BinarySearchTree From 04714251f1747c562d8b89613dc14e7b5dfe4c11 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:02:23 +0500 Subject: [PATCH 23/33] Added seed when calling random as suggested Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/tests/test_binary_trees.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index 4d9874d58..278b31780 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -360,6 +360,8 @@ def test_CartesianTree(): assert tree.delete(18) is None def test_Treap(): + + random.seed(0) tree = Treap() tree.insert(7,7) tree.insert(2,2) From 27df682fd54a17dd31a36afcb09c9f41a0c8ca20 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:03:03 +0500 Subject: [PATCH 24/33] As suggested to add space when defining `__slots__` Co-Authored-By: Gagandeep Singh --- pydatastructs/utils/misc_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pydatastructs/utils/misc_util.py b/pydatastructs/utils/misc_util.py index faaf81b02..e476a5fb1 100644 --- a/pydatastructs/utils/misc_util.py +++ b/pydatastructs/utils/misc_util.py @@ -69,6 +69,7 @@ class CartesianTreeNode(TreeNode): """ __slots__ = ['key', 'data', 'priority'] + def __new__(cls, key, priority, data=None): obj = TreeNode.__new__(cls, key, data) obj.priority = priority From f1245a43dc620a7720a3cded7d2681bb50dfa4e6 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:03:35 +0500 Subject: [PATCH 25/33] As suggested to add spaces between commas Co-Authored-By: Gagandeep Singh --- pydatastructs/trees/tests/test_binary_trees.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index 278b31780..bab23ccc6 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -363,11 +363,11 @@ def test_Treap(): random.seed(0) tree = Treap() - tree.insert(7,7) - tree.insert(2,2) - tree.insert(3,3) - tree.insert(4,4) - tree.insert(5,5) + tree.insert(7, 7) + tree.insert(2, 2) + tree.insert(3, 3) + tree.insert(4, 4) + tree.insert(5, 5) assert isinstance(tree.tree[0].priority, float) tree.delete(1) assert tree.search(1) is None From 59f2539233fbb9f5e43c58a584195806c116df41 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:21:22 +0500 Subject: [PATCH 26/33] Made `data` an optional argument in both `CartesianTree` and `Treap` --- pydatastructs/trees/binary_trees.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 4ba521a52..ee36642a8 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -704,7 +704,7 @@ def _trickle_down(self, node_idx): node = self.tree[node_idx] parent_idx = node.parent - def insert(self, key, data, priority): + def insert(self, key, priority, data=None): super(CartesianTree, self).insert(key, data) node_idx = super(CartesianTree, self).search(key) node = self.tree[node_idx] @@ -764,12 +764,12 @@ class Treap(CartesianTree): """ priorities = set() - def insert(self, key, data): + def insert(self, key, data = None): priority = random.random() while priority in self.priorities: priority = random.random() self.priorities.add(priority) - super(Treap, self).insert(key, data, priority) + super(Treap, self).insert(key, priority, data) class AVLTree(SelfBalancingBinaryTree): """ From 5bfa2bb44139561d1bf8d4899831174748a115e7 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:22:26 +0500 Subject: [PATCH 27/33] Added spaces in commas in test Co-Authored-By: Gagandeep Singh --- pydatastructs/utils/tests/test_misc_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/utils/tests/test_misc_util.py b/pydatastructs/utils/tests/test_misc_util.py index 42fe876d9..f548caa90 100644 --- a/pydatastructs/utils/tests/test_misc_util.py +++ b/pydatastructs/utils/tests/test_misc_util.py @@ -40,5 +40,5 @@ def test_MAryTreeNode(): assert str(m.children) == "['2', '3', '4', '5', '6', '7', '8', '9']" def test_CartesianTreeNode(): - c = CartesianTreeNode(1,1,1) + c = CartesianTreeNode(1, 1, 1) assert str(c) == "(None, 1, 1, 1, None)" From e7cbfb83346352c27dc6eb54c9bb1d39c5b53292 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:34:44 +0500 Subject: [PATCH 28/33] Updated docs according to the change in API --- pydatastructs/trees/binary_trees.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index ee36642a8..c16ced155 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -645,8 +645,8 @@ class CartesianTree(SelfBalancingBinaryTree): >>> from pydatastructs.trees import CartesianTree as CT >>> c = CT() - >>> c.insert(1, 1, 4) - >>> c.insert(2, 2, 3) + >>> c.insert(1, 4, 1) + >>> c.insert(2, 3, 2) >>> child = c.tree[c.root_idx].left >>> c.tree[child].data 1 From 628ad518a400572e823d365cdffb0bf7e0b60844 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:37:34 +0500 Subject: [PATCH 29/33] Updated tests with the change in API --- .../trees/tests/test_binary_trees.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index bab23ccc6..3994ac58c 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -323,16 +323,16 @@ def test_BinaryIndexedTree(): def test_CartesianTree(): tree = CartesianTree() - tree.insert(3, 3, 1) - tree.insert(1, 1, 6) - tree.insert(0, 0, 9) - tree.insert(5, 5, 11) - tree.insert(4, 4, 14) - tree.insert(9, 9, 17) - tree.insert(7, 7, 22) - tree.insert(6, 6, 42) - tree.insert(8, 8, 49) - tree.insert(2, 2, 99) + tree.insert(3, 1, 3) + tree.insert(1, 6, 1) + tree.insert(0, 9, 0) + tree.insert(5, 11, 5) + tree.insert(4, 14, 4) + tree.insert(9, 17, 9) + tree.insert(7, 22, 7) + tree.insert(6, 42, 6) + tree.insert(8, 49, 8) + tree.insert(2, 99, 2) assert str(tree) == \ ("[(1, 3, 1, 3, 3), (2, 1, 6, 1, 9), " "(None, 0, 9, 0, None), (4, 5, 11, 5, 5), " From b47578038cc3a03634a7db9af5e7e28a01fa6fe0 Mon Sep 17 00:00:00 2001 From: Aimaanhasan <39834215+Aimaanhasan@users.noreply.github.com> Date: Fri, 24 Apr 2020 17:46:48 +0500 Subject: [PATCH 30/33] Assertion error fix --- pydatastructs/trees/tests/test_binary_trees.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/trees/tests/test_binary_trees.py b/pydatastructs/trees/tests/test_binary_trees.py index 3994ac58c..22339e005 100644 --- a/pydatastructs/trees/tests/test_binary_trees.py +++ b/pydatastructs/trees/tests/test_binary_trees.py @@ -339,7 +339,7 @@ def test_CartesianTree(): "(None, 4, 14, 4, None), (6, 9, 17, 9, None), " "(7, 7, 22, 7, 8), (None, 6, 42, 6, None), " "(None, 8, 49, 8, None), (None, 2, 99, 2, None)]") - tree.insert(1.5, 1.5, 4) + tree.insert(1.5, 4, 1.5) assert str(tree) == \ ("[(10, 3, 1, 3, 3), (2, 1, 6, 1, None), " "(None, 0, 9, 0, None), (4, 5, 11, 5, 5), " From d1a41c86d7856d54e2dff8f7b02b55690eb729f8 Mon Sep 17 00:00:00 2001 From: czgdp1807 Date: Fri, 24 Apr 2020 18:48:16 +0530 Subject: [PATCH 31/33] some minor changes --- pydatastructs/trees/binary_trees.py | 17 ++++++++++------- pydatastructs/utils/tests/test_code_quality.py | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index 7044846cf..cb2412a2f 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -683,6 +683,11 @@ class CartesianTree(SelfBalancingBinaryTree): pydatastructs.trees.binary_tree.SelfBalancingBinaryTree """ + + @classmethod + def methods(cls): + return ['__str__', 'insert', 'delete'] + def _bubble_up(self, node_idx): node = self.tree[node_idx] parent_idx = self.tree[node_idx].parent @@ -701,7 +706,6 @@ def _bubble_up(self, node_idx): def _trickle_down(self, node_idx): node = self.tree[node_idx] - parent_idx = node.parent while node.left is not None or node.right is not None: if node.left is None: self._left_rotate(node_idx, self.tree[node_idx].right) @@ -712,7 +716,6 @@ def _trickle_down(self, node_idx): else: self._left_rotate(node_idx, self.tree[node_idx].right) node = self.tree[node_idx] - parent_idx = node.parent def insert(self, key, priority, data=None): super(CartesianTree, self).insert(key, data) @@ -773,12 +776,12 @@ class Treap(CartesianTree): .. [1] https://en.wikipedia.org/wiki/Treap """ - priorities = set() - def insert(self, key, data = None): + @classmethod + def methods(cls): + return ['insert'] + + def insert(self, key, data=None): priority = random.random() - while priority in self.priorities: - priority = random.random() - self.priorities.add(priority) super(Treap, self).insert(key, priority, data) class AVLTree(SelfBalancingBinaryTree): diff --git a/pydatastructs/utils/tests/test_code_quality.py b/pydatastructs/utils/tests/test_code_quality.py index 350100f5d..828941493 100644 --- a/pydatastructs/utils/tests/test_code_quality.py +++ b/pydatastructs/utils/tests/test_code_quality.py @@ -95,7 +95,8 @@ def _apis(): pyds.miscellaneous_data_structures.stack.LinkedListStack, pyds.DisjointSetForest, pyds.BinomialTree, pyds.TreeNode, pyds.MAryTreeNode, pyds.LinkedListNode, pyds.BinomialTreeNode, pyds.AdjacencyListGraphNode, - pyds.AdjacencyMatrixGraphNode, pyds.GraphEdge, pyds.Set, pyds.BinaryIndexedTree] + pyds.AdjacencyMatrixGraphNode, pyds.GraphEdge, pyds.Set, pyds.BinaryIndexedTree, + pyds.CartesianTree, pyds.CartesianTreeNode, pyds.Treap] def test_public_api(): pyds = pydatastructs From 542031389b088ff4ed3b0d6345b92104b48f691c Mon Sep 17 00:00:00 2001 From: czgdp1807 Date: Fri, 24 Apr 2020 19:21:24 +0530 Subject: [PATCH 32/33] some minor changes --- pydatastructs/trees/binary_trees.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index cb2412a2f..f291d3982 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -683,7 +683,6 @@ class CartesianTree(SelfBalancingBinaryTree): pydatastructs.trees.binary_tree.SelfBalancingBinaryTree """ - @classmethod def methods(cls): return ['__str__', 'insert', 'delete'] From cd6852b31f992db74ee4630502c2ee90de539379 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Fri, 24 Apr 2020 19:25:33 +0530 Subject: [PATCH 33/33] Apply suggestions from code review --- pydatastructs/trees/binary_trees.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/trees/binary_trees.py b/pydatastructs/trees/binary_trees.py index f291d3982..53df522b4 100644 --- a/pydatastructs/trees/binary_trees.py +++ b/pydatastructs/trees/binary_trees.py @@ -7,7 +7,6 @@ import random from copy import deepcopy - __all__ = [ 'AVLTree', 'BinaryTree',