dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def RangeTraversal ( root , n1 , n2 ) :
    if root == None :
        return
    curr = root
    while curr :
        if curr . left == None :
            if curr . data <= n2 and curr . data >= n1 :
                print ( curr . data , end = " ▁ " )
            curr = curr . right
        else :
            pre = curr . left
            while ( pre . right != None and pre . right != curr ) :
                pre = pre . right
            if pre . right == None :
                pre . right = curr ;
                curr = curr . left
            else :
                pre . right = None
                if curr . data <= n2 and curr . data >= n1 :
                    print ( curr . data , end = " ▁ " )
                curr = curr . right
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 4 )
    root . left = newNode ( 2 )
    root . right = newNode ( 7 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 3 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 10 )
    RangeTraversal ( root , 4 , 12 )

Class/struct names: newNode
Python program:
def inRange ( root , low , high ) :
    return root . data >= low and root . data <= high
def getCountUtil ( root , low , high , count ) :
    if root == None :
        return True
    l = getCountUtil ( root . left , low , high , count )
    r = getCountUtil ( root . right , low , high , count )
    if l and r and inRange ( root , low , high ) :
        count [ 0 ] += 1
        return True
    return False
def getCount ( root , low , high ) :
    count = [ 0 ]
    getCountUtil ( root , low , high , count )
    return count
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 5 )
    root . right = newNode ( 50 )
    root . left . left = newNode ( 1 )
    root . right . left = newNode ( 40 )
    root . right . right = newNode ( 100 )
    l = 5
    h = 45
    print ( " Count ▁ of ▁ subtrees ▁ in ▁ [ " , l , " , ▁ " , h , " ] ▁ is ▁ " , getCount ( root , l , h ) )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def insert ( root , data ) :
    if root == None :
        return newNode ( data )
    if data < root . data :
        root . left = insert ( root . left , data )
    elif data > root . data :
        root . right = insert ( root . right , data )
    return root
def inorder ( root ) :
    if root != None :
        inorder ( root . left )
        print ( root . data , end = " ▁ " )
        inorder ( root . right )
def leafDelete ( root ) :
    if root == None :
        return None
    if root . left == None and root . right == None :
        return None
    root . left = leafDelete ( root . left )
    root . right = leafDelete ( root . right )
    return root
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 20 )
    insert ( root , 10 )
    insert ( root , 5 )
    insert ( root , 15 )
    insert ( root , 30 )
    insert ( root , 25 )
    insert ( root , 35 )
    print ( " Inorder ▁ before ▁ Deleting ▁ the ▁ leaf ▁ Node . " )
    inorder ( root )
    leafDelete ( root )
    print ( )
    print ( " INorder ▁ after ▁ Deleting ▁ the ▁ leaf ▁ Node . " )
    inorder ( root )

Class/struct names: newNode
Python program:
INT_MAX = 2147483647
class createNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def insert ( root , key ) :
    if ( root == None ) :
        return createNode ( key )
    if ( root . data > key ) :
        root . left = insert ( root . left , key )
    elif ( root . data < key ) :
        root . right = insert ( root . right , key )
    return root
def ksmallestElementSumRec ( root , k , count ) :
    if ( root == None ) :
        return 0
    if ( count [ 0 ] > k [ 0 ] ) :
        return 0
    res = ksmallestElementSumRec ( root . left , k , count )
    if ( count [ 0 ] >= k [ 0 ] ) :
        return res
    res += root . data
    count [ 0 ] += 1
    if ( count [ 0 ] >= k [ 0 ] ) :
        return res
    return res + ksmallestElementSumRec ( root . right , k , count )
def ksmallestElementSum ( root , k ) :
    count = [ 0 ]
    return ksmallestElementSumRec ( root , k , count )
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 20 )
    root = insert ( root , 8 )
    root = insert ( root , 4 )
    root = insert ( root , 12 )
    root = insert ( root , 10 )
    root = insert ( root , 14 )
    root = insert ( root , 22 )
    k = [ 3 ]
    print ( ksmallestElementSum ( root , k ) )

Class/struct names: createNode
Python program:
class createNode :
    def __init__ ( self , data ) :
        self . data = data
        self . lCount = 0
        self . Sum = 0
        self . left = None
        self . right = None
def insert ( root , key ) :
    if root == None :
        return createNode ( key )
    if root . data > key :
        root . lCount += 1
        root . Sum += key
        root . left = insert ( root . left , key )
    elif root . data < key :
        root . right = insert ( root . right , key )
    return root
def ksmallestElementSumRec ( root , k , temp_sum ) :
    if root == None :
        return
    if ( root . lCount + 1 ) == k :
        temp_sum [ 0 ] += root . data + root . Sum
        return
    elif k > root . lCount :
        temp_sum [ 0 ] += root . data + root . Sum
        k = k - ( root . lCount + 1 )
        ksmallestElementSumRec ( root . right , k , temp_sum )
    else :
        ksmallestElementSumRec ( root . left , k , temp_sum )
def ksmallestElementSum ( root , k ) :
    Sum = [ 0 ]
    ksmallestElementSumRec ( root , k , Sum )
    return Sum [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 20 )
    root = insert ( root , 8 )
    root = insert ( root , 4 )
    root = insert ( root , 12 )
    root = insert ( root , 10 )
    root = insert ( root , 14 )
    root = insert ( root , 22 )
    k = 3
    print ( ksmallestElementSum ( root , k ) )

Class/struct names: createNode
Python program:
class getnode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def find_p_s ( root , a , p , q ) :
    if ( not root ) :
        return
    find_p_s ( root . left , a , p , q )
    if ( root and root . data > a ) :
        if ( ( not q [ 0 ] ) or q [ 0 ] and q [ 0 ] . data > root . data ) :
            q [ 0 ] = root
    elif ( root and root . data < a ) :
        p [ 0 ] = root
    find_p_s ( root . right , a , p , q )
if __name__ == ' _ _ main _ _ ' :
    root1 = getnode ( 50 )
    root1 . left = getnode ( 20 )
    root1 . right = getnode ( 60 )
    root1 . left . left = getnode ( 10 )
    root1 . left . right = getnode ( 30 )
    root1 . right . left = getnode ( 55 )
    root1 . right . right = getnode ( 70 )
    p = [ None ]
    q = [ None ]
    find_p_s ( root1 , 55 , p , q )
    if ( p [ 0 ] ) :
        print ( p [ 0 ] . data , end = " " )
    if ( q [ 0 ] ) :
        print ( " " , q [ 0 ] . data )

Class/struct names: getnode
Python program:
def findPreSuc ( root , pre , suc , key ) :
    if root == None :
        return
    while root != None :
        if root . key == key :
            if root . right :
                suc [ 0 ] = root . right
                while suc [ 0 ] . left :
                    suc [ 0 ] = suc [ 0 ] . left
            if root . left :
                pre [ 0 ] = root . left
                while pre [ 0 ] . right :
                    pre [ 0 ] = pre [ 0 ] . right
            return
        elif root . key < key :
            pre [ 0 ] = root
            root = root . right
        else :
            suc [ 0 ] = root
            root = root . left
class newNode :
    def __init__ ( self , data ) :
        self . key = data
        self . left = None
        self . right = None
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        node . left = insert ( node . left , key )
    else :
        node . right = insert ( node . right , key )
    return node
if __name__ == ' _ _ main _ _ ' :
    key = 65
    root = None
    root = insert ( root , 50 )
    insert ( root , 30 )
    insert ( root , 20 )
    insert ( root , 40 )
    insert ( root , 70 )
    insert ( root , 60 )
    insert ( root , 80 )
    pre , suc = [ None ] , [ None ]
    findPreSuc ( root , pre , suc , key )
    if pre [ 0 ] != None :
        print ( " Predecessor ▁ is " , pre [ 0 ] . key )
    else :
        print ( " - 1" )
    if suc [ 0 ] != None :
        print ( " Successor ▁ is " , suc [ 0 ] . key )
    else :
        print ( " - 1" )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def insert ( root , key ) :
    if root == None :
        return newNode ( key )
    if root . data > key :
        root . left = insert ( root . left , key )
    else :
        root . right = insert ( root . right , key )
    return root
def storeInorder ( ptr , vect ) :
    if ptr == None :
        return
    storeInorder ( ptr . left , vect )
    vect . append ( ptr . data )
    storeInorder ( ptr . right , vect )
def pairSumUtil ( vect1 , vect2 , Sum ) :
    left = 0
    right = len ( vect2 ) - 1
    while left < len ( vect1 ) and right >= 0 :
        if vect1 [ left ] + vect2 [ right ] == Sum :
            print ( " ( " , vect1 [ left ] , " , " , vect2 [ right ] , " ) , " , end = " ▁ " )
            left += 1
            right -= 1
        elif vect1 [ left ] + vect2 [ right ] < Sum :
            left += 1
        else :
            right -= 1
def pairSum ( root1 , root2 , Sum ) :
    vect1 = [ ]
    vect2 = [ ]
    storeInorder ( root1 , vect1 )
    storeInorder ( root2 , vect2 )
    pairSumUtil ( vect1 , vect2 , Sum )
if __name__ == ' _ _ main _ _ ' :
    root1 = None
    root1 = insert ( root1 , 8 )
    root1 = insert ( root1 , 10 )
    root1 = insert ( root1 , 3 )
    root1 = insert ( root1 , 6 )
    root1 = insert ( root1 , 1 )
    root1 = insert ( root1 , 5 )
    root1 = insert ( root1 , 7 )
    root1 = insert ( root1 , 14 )
    root1 = insert ( root1 , 13 )
    root2 = None
    root2 = insert ( root2 , 5 )
    root2 = insert ( root2 , 18 )
    root2 = insert ( root2 , 2 )
    root2 = insert ( root2 , 1 )
    root2 = insert ( root2 , 3 )
    root2 = insert ( root2 , 4 )
    Sum = 10
    pairSum ( root1 , root2 , Sum )

Index/key variables: left, right
Class/struct names: newNode
Python program:
class newnode :
    def __init__ ( self , data ) :
        self . key = data
        self . left = None
        self . right = None
def maxDiffUtil ( ptr , k , min_diff , min_diff_key ) :
    if ptr == None :
        return
    if ptr . key == k :
        min_diff_key [ 0 ] = k
        return
    if min_diff > abs ( ptr . key - k ) :
        min_diff = abs ( ptr . key - k )
        min_diff_key [ 0 ] = ptr . key
    if k < ptr . key :
        maxDiffUtil ( ptr . left , k , min_diff , min_diff_key )
    else :
        maxDiffUtil ( ptr . right , k , min_diff , min_diff_key )
def maxDiff ( root , k ) :
    min_diff , min_diff_key = 999999999999 , [ - 1 ]
    maxDiffUtil ( root , k , min_diff , min_diff_key )
    return min_diff_key [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = newnode ( 9 )
    root . left = newnode ( 4 )
    root . right = newnode ( 17 )
    root . left . left = newnode ( 3 )
    root . left . right = newnode ( 6 )
    root . left . right . left = newnode ( 5 )
    root . left . right . right = newnode ( 7 )
    root . right . right = newnode ( 22 )
    root . right . right . left = newnode ( 20 )
    k = 18
    print ( maxDiff ( root , k ) )

Class/struct names: newnode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def insertLevelOrder ( arr , root , i , n ) :
    if i < n :
        temp = newNode ( arr [ i ] )
        root = temp
        root . left = insertLevelOrder ( arr , root . left , 2 * i + 1 , n )
        root . right = insertLevelOrder ( arr , root . right , 2 * i + 2 , n )
    return root
def inOrder ( root ) :
    if root != None :
        inOrder ( root . left )
        print ( root . data , end = " ▁ " )
        inOrder ( root . right )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 6 , 6 , 6 ]
    n = len ( arr )
    root = None
    root = insertLevelOrder ( arr , root , 0 , n )
    inOrder ( root )

Index/key variables: i
Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def constructTreeUtil ( pre : list , post : list , l : int , h : int , size : int ) -> Node :
    global preIndex
    if ( preIndex >= size or l > h ) :
        return None
    root = Node ( pre [ preIndex ] )
    preIndex += 1
    if ( l == h or preIndex >= size ) :
        return root
    i = l
    while i <= h :
        if ( pre [ preIndex ] == post [ i ] ) :
            break
        i += 1
    if ( i <= h ) :
        root . left = constructTreeUtil ( pre , post , l , i , size )
        root . right = constructTreeUtil ( pre , post , i + 1 , h , size )
    return root
def constructTree ( pre : list , post : list , size : int ) -> Node :
    global preIndex
    return constructTreeUtil ( pre , post , 0 , size - 1 , size )
def printInorder ( node : Node ) -> None :
    if ( node is None ) :
        return
    printInorder ( node . left )
    print ( node . data , end = " ▁ " )
    printInorder ( node . right )
if __name__ == " _ _ main _ _ " :
    pre = [ 1 , 2 , 4 , 8 , 9 , 5 , 3 , 6 , 7 ]
    post = [ 8 , 9 , 4 , 5 , 2 , 6 , 7 , 3 , 1 ]
    size = len ( pre )
    preIndex = 0
    root = constructTree ( pre , post , size )
    print ( " Inorder ▁ traversal ▁ of ▁ " " the ▁ constructed ▁ tree : ▁ " )
    printInorder ( root )

Index/key variables: i, preIndex
Class/struct names: Node
Python program:
def createThreaded ( root ) :
    if root == None :
        return None
    if root . left == None and root . right == None :
        return root
    if root . left != None :
        l = createThreaded ( root . left )
        l . right = root
        l . isThreaded = True
    if root . right == None :
        return root
    return createThreaded ( root . right )
def leftMost ( root ) :
    while root != None and root . left != None :
        root = root . left
    return root
def inOrder ( root ) :
    if root == None :
        return
    cur = leftMost ( root )
    while cur != None :
        print ( cur . key , end = " ▁ " )
        if cur . isThreaded :
            cur = cur . right
        else :
            cur = leftMost ( cur . right )
class newNode :
    def __init__ ( self , key ) :
        self . left = self . right = None
        self . key = key
        self . isThreaded = None
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    createThreaded ( root )
    print ( " Inorder ▁ traversal ▁ of ▁ created " , " threaded ▁ tree ▁ is " )
    inOrder ( root )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . key = item
        self . parent = self . left = self . right = None
def insert ( node , key ) :
    if node == None :
        return newNode ( key )
    if key < node . key :
        node . left = insert ( node . left , key )
        node . left . parent = node
    elif key > node . key :
        node . right = insert ( node . right , key )
        node . right . parent = node
    return node
def inorder ( root ) :
    leftdone = False
    while root :
        if leftdone == False :
            while root . left :
                root = root . left
        print ( root . key , end = " ▁ " )
        leftdone = True
        if root . right :
            leftdone = False
            root = root . right
        elif root . parent :
            while root . parent and root == root . parent . right :
                root = root . parent
            if root . parent == None :
                break
            root = root . parent
        else :
            break
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 24 )
    root = insert ( root , 27 )
    root = insert ( root , 29 )
    root = insert ( root , 34 )
    root = insert ( root , 14 )
    root = insert ( root , 4 )
    root = insert ( root , 10 )
    root = insert ( root , 22 )
    root = insert ( root , 13 )
    root = insert ( root , 3 )
    root = insert ( root , 2 )
    root = insert ( root , 6 )
    print ( " Inorder ▁ traversal ▁ is ▁ " )
    inorder ( root )

Boolean variables: leftdone
Class/struct names: newNode
Python program:
def printSorted ( arr , start , end ) :
    if start > end :
        return
    printSorted ( arr , start * 2 + 1 , end )
    print ( arr [ start ] , end = " ▁ " )
    printSorted ( arr , start * 2 + 2 , end )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 5 , 1 , 3 ]
    arr_size = len ( arr )
    printSorted ( arr , 0 , arr_size - 1 )

Index/key variables: start
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def prInorder ( node ) :
    if ( node == None ) :
        return
    prInorder ( node . left )
    print ( node . data , end = " ▁ " )
    prInorder ( node . right )
def constructBinaryTreeUtil ( pre , preM , preIndex , l , h , size ) :
    if ( preIndex >= size or l > h ) :
        return None , preIndex
    root = newNode ( pre [ preIndex ] )
    preIndex += 1
    if ( l == h ) :
        return root , preIndex
    i = 0
    for i in range ( l , h + 1 ) :
        if ( pre [ preIndex ] == preM [ i ] ) :
            break
    if ( i <= h ) :
        root . left , preIndex = constructBinaryTreeUtil ( pre , preM , preIndex , i , h , size )
        root . right , preIndex = constructBinaryTreeUtil ( pre , preM , preIndex , l + 1 , i - 1 , size )
    return root , preIndex
def constructBinaryTree ( root , pre , preMirror , size ) :
    preIndex = 0
    preMIndex = 0
    root , x = constructBinaryTreeUtil ( pre , preMirror , preIndex , 0 , size - 1 , size )
    prInorder ( root )
if __name__ == " _ _ main _ _ " :
    preOrder = [ 1 , 2 , 4 , 5 , 3 , 6 , 7 ]
    preOrderMirror = [ 1 , 3 , 7 , 6 , 2 , 5 , 4 ]
    size = 7
    root = newNode ( 0 )
    constructBinaryTree ( root , preOrder , preOrderMirror , size )

Index/key variables: i, preIndex
Iterator variables: i
Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def floorCeilBSTHelper ( root , key ) :
    global floor , ceil
    while ( root ) :
        if ( root . data == key ) :
            ceil = root . data
            floor = root . data
            return
        if ( key > root . data ) :
            floor = root . data
            root = root . right
        else :
            ceil = root . data
            root = root . left
def floorCeilBST ( root , key ) :
    global floor , ceil
    floor = - 1
    ceil = - 1
    floorCeilBSTHelper ( root , key )
    print ( key , floor , ceil )
if __name__ == ' _ _ main _ _ ' :
    floor , ceil = - 1 , - 1
    root = Node ( 8 )
    root . left = Node ( 4 )
    root . right = Node ( 12 )
    root . left . left = Node ( 2 )
    root . left . right = Node ( 6 )
    root . right . left = Node ( 10 )
    root . right . right = Node ( 14 )
    for i in range ( 16 ) :
        floorCeilBST ( root , i )

Iterator variables: i
Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . key = data
        self . count = 1
        self . left = None
        self . right = None
def inorder ( root ) :
    if root != None :
        inorder ( root . left )
        print ( root . key , " ( " , root . count , " ) " , end = " ▁ " )
        inorder ( root . right )
def insert ( node , key ) :
    if node == None :
        k = newNode ( key )
        return k
    if key == node . key :
        ( node . count ) += 1
        return node
    if key < node . key :
        node . left = insert ( node . left , key )
    else :
        node . right = insert ( node . right , key )
    return node
def minValueNode ( node ) :
    current = node
    while current . left != None :
        current = current . left
    return current
def deleteNode ( root , key ) :
    if root == None :
        return root
    if key < root . key :
        root . left = deleteNode ( root . left , key )
    elif key > root . key :
        root . right = deleteNode ( root . right , key )
    else :
        if root . count > 1 :
            root . count -= 1
            return root
        if root . left == None :
            temp = root . right
            return temp
        elif root . right == None :
            temp = root . left
            return temp
        temp = minValueNode ( root . right )
        root . key = temp . key
        root . right = deleteNode ( root . right , temp . key )
    return root
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 12 )
    root = insert ( root , 10 )
    root = insert ( root , 20 )
    root = insert ( root , 9 )
    root = insert ( root , 11 )
    root = insert ( root , 10 )
    root = insert ( root , 12 )
    root = insert ( root , 12 )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ given ▁ tree " )
    inorder ( root )
    print ( )
    print ( " Delete ▁ 20" )
    root = deleteNode ( root , 20 )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree " )
    inorder ( root )
    print ( )
    print ( " Delete ▁ 12" )
    root = deleteNode ( root , 12 )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree " )
    inorder ( root )
    print ( )
    print ( " Delete ▁ 9" )
    root = deleteNode ( root , 9 )
    print ( " Inorder ▁ traversal ▁ of ▁ the ▁ modified ▁ tree " )
    inorder ( root )

Class/struct names: newNode