Python Forum
How we prune Alphabeta Tree Node Using BST concept
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How we prune Alphabeta Tree Node Using BST concept
#1
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
Reply
#2
looks to be addressed here: https://leetcode.com/problems/trim-a-bin...arch-tree/
Reply
#3
@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.
Reply
#4
Google is your friend,
try: https://www.cs.cornell.edu/courses/cs312.../rec21.htm
Reply
#5
@Larz60+ thanks you got it some but it is not really related to me code as what next i want to do
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [XML] How to remove node? Winfried 0 655 May-29-2020, 02:50 PM
Last Post: Winfried
  Adding a node into an xml tree arbiel 7 1,123 May-05-2020, 09:55 PM
Last Post: arbiel
  Understanding the concept ( Modules , imports ) erfanakbari1 1 632 Nov-25-2019, 01:59 AM
Last Post: Larz60+
  Understand for range concept RavCOder 4 1,008 Oct-29-2019, 02:26 PM
Last Post: newbieAuggie2019
  help with multiprocess concept kiyoshi7 2 930 Aug-10-2019, 08:19 PM
Last Post: kiyoshi7
  Recursion concept Truman 8 4,699 Oct-06-2018, 07:48 AM
Last Post: Larz60+
  Concept of batch files Truman 2 1,454 Jul-23-2018, 09:02 PM
Last Post: Truman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020