Python Forum

Full Version: How we prune Alphabeta Tree Node Using BST concept
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
@Larz60 the concept of Trim a Binary Search Tree are applicable where we need to arrangement of nodes like if want to remove some nodes from specific range for any the BST so some node can be removed by this way for specific structure and design of any BST so this idea is not applicable only Alpha Beta Concept can be applicable to prune node if someone want to demonstrate the concept of BST with Alpha Beta, pruning.
@Larz60+ thanks you got it some but it is not really related to me code as what next i want to do