May-17-2021, 07:47 AM

Quote:I implement an alpha beta Binary search for some specific proposes like how to get the different optimal Value but however don't know how prune the node in Alphabet BST tree for list of node pruned as i know but for exact node I don't know find the same code below

def pruneTree_recursion(root): if root is None: return None root.left = pruneTree_recursion(root.left) root.right = pruneTree_recursion(root.right) return root if root.val == 1 or root.left or root.right else None def pruneTree(root): def postorder(root, orderlist): if root: postorder(root.left, orderlist) postorder(root.right, orderlist) orderlist.append(root) return orderlist orderlist = postorder(root, []) for node in orderlist: if node.val == 0: if (node.left is None) and (node.right is None): node = None return root