dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
dp = [ [ - 1 for i in range ( 2 ) ] for j in range ( 1000 ) ]
def IsSumEqualsXor ( i , n , bound , s ) :
    if ( i == n ) :
        return 1
    if ( dp [ i ] [ bound ] != - 1 ) :
        return dp [ i ] [ bound ]
    ans = 0
    if ( bound and s [ i ] == '0' ) :
        ans = IsSumEqualsXor ( i + 1 , n , 1 , s )
    else :
        ans = 2 * IsSumEqualsXor ( i + 1 , n , bound & ( s [ i ] == '1' ) , s )
        ans += IsSumEqualsXor ( i + 1 , n , 0 , s )
    dp [ i ] [ bound ] = ans
    return ans
def convertToBinary ( n ) :
    ans = [ ]
    while ( n ) :
        rem = chr ( n % 2 + 48 )
        ans . append ( rem )
        n //= 2
    ans = ans [ : : - 1 ]
    return ans
def IsSumEqualsXorUtil ( N ) :
    s = convertToBinary ( N )
    print ( IsSumEqualsXor ( 0 , len ( s ) , 1 , s ) )
if __name__ == ' _ _ main _ _ ' :
    N = 10
    IsSumEqualsXorUtil ( N )

Index/key variables: bound, i
Accumulator variables: ans, n
Python program:
def printMat ( degseq , n ) :
    mat = [ [ 0 ] * n for i in range ( n ) ]
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :
                degseq [ i ] -= 1
                degseq [ j ] -= 1
                mat [ i ] [ j ] = 1
                mat [ j ] [ i ] = 1
    print ( " ▁ " , end = " ▁ " )
    for i in range ( n ) :
        print ( " ▁ " , " ( " , i , " ) " , end = " " )
    print ( )
    print ( )
    for i in range ( n ) :
        print ( " ▁ " , " ( " , i , " ) " , end = " " )
        for j in range ( n ) :
            print ( " ▁ " , mat [ i ] [ j ] , end = " " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    degseq = [ 2 , 2 , 1 , 1 , 1 ]
    n = len ( degseq )
    printMat ( degseq , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findDecimal ( arr , N ) :
    power = 0 ;
    result = 0 ;
    for i in range ( N - 1 , - 1 , - 1 ) :
        bit = abs ( int ( arr [ i ] ) - round ( arr [ i ] ) ) ;
        if ( bit ) :
            result += pow ( 2 , power ) ;
        power += 1 ;
    print ( result ) ;
arr = [ 1.2 , 2.6 , 4.2 , 6.9 , 3.1 , 21.6 , 91.2 ] ;
N = len ( arr )
findDecimal ( arr , N ) ;

Index/key variables: i
Accumulator variables: power, result
Iterator variables: i
Python program:
def totalMoney ( N ) :
    ans = 0
    for i in range ( 0 , N ) :
        ans += i / 7
        ans += ( i % 7 + 1 )
    return ans
N = 15
print ( totalMoney ( N ) )

Accumulator variables: ans
Iterator variables: i
Python program:
class pair :
    def __init__ ( self , count , prevIndex ) :
        self . count = count ;
        self . prevIndex = prevIndex ;
def findSum ( arr , n ) :
    map = { } ;
    left = [ 0 for i in range ( n ) ] ;
    right = [ 0 for i in range ( n ) ] ;
    for i in range ( n ) :
        if ( arr [ i ] not in map ) :
            left [ i ] = 0 ;
            map [ arr [ i ] ] = pair ( 1 , i ) ;
        else :
            tmp = map [ arr [ i ] ] ;
            left [ i ] = ( tmp . count ) * ( i - tmp . prevIndex ) + left [ tmp . prevIndex ]
            map [ arr [ i ] ] = pair ( tmp . count + 1 , i ) ;
    map . clear ( ) ;
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( arr [ i ] not in map ) :
            right [ i ] = 0 ;
            map [ arr [ i ] ] = pair ( 1 , i ) ;
        else :
            tmp = map [ arr [ i ] ] ;
            right [ i ] = ( tmp . count ) * ( abs ( i - tmp . prevIndex ) ) + right [ tmp . prevIndex ] ;
            map [ arr [ i ] ] = pair ( tmp . count + 1 , i ) ;
    for i in range ( n ) :
        print ( left [ i ] + right [ i ] , end = " ▁ " ) ;
arr = [ 1 , 3 , 1 , 1 , 2 ] ;
N = len ( arr ) ;
findSum ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Class/struct names: pair
Python program:
from collections import deque
def isPresent ( n , x ) :
    num = str ( n )
    for i in range ( len ( num ) ) :
        if ( ( ord ( num [ i ] ) - ord ( '0' ) ) == x ) :
            return i
    return - 1
def removeDigit ( n , index ) :
    num = str ( n )
    ans = " "
    for i in range ( len ( num ) ) :
        if ( i != index ) :
            ans += num [ i ]
    if ( ans == " " or ( len ( ans ) == 1 and ans [ 0 ] == '0' ) ) :
        return - 1
    x = int ( ans )
    return x
def reduceNtoX ( a , b , d , n ) :
    q = deque ( )
    q . append ( a )
    visited = { }
    visited [ a ] = True
    while ( len ( q ) > 0 ) :
        top = q . popleft ( )
        if ( top < 0 ) :
            continue
        if ( top == b ) :
            return True
        for i in range ( n ) :
            if ( d [ i ] != 0 and top % d [ i ] == 0 and ( top // d [ i ] not in visited ) ) :
                q . append ( top // d [ i ] )
                visited [ top // d [ i ] ] = True
            index = isPresent ( top , d [ i ] )
            if ( index != - 1 ) :
                newElement = removeDigit ( top , index )
                if ( newElement != - 1 and ( newElement not in visited ) ) :
                    q . append ( newElement )
                    visited [ newElement ] = True
    return False
if __name__ == ' _ _ main _ _ ' :
    A , B = 5643 , 81
    D = [ 3 , 8 , 1 ]
    N = len ( D )
    if ( reduceNtoX ( A , B , D , N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: a, i, newElement
Accumulator variables: ans, q
Iterator variables: i
Python program:
MAX = 50
import sys
from math import sqrt , gcd
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    for i in range ( 5 , int ( sqrt ( n ) ) + 1 , 6 ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
    return True
def findPrime ( primes ) :
    global MAX
    for i in range ( 2 , MAX + 1 , 1 ) :
        if ( isPrime ( i ) ) :
            primes . append ( i )
def findMinimumNumber ( arr , N ) :
    primes = [ ]
    findPrime ( primes )
    ans = sys . maxsize
    n = len ( primes )
    for i in range ( 1 , ( 1 << n ) , 1 ) :
        temp = 1
        for j in range ( n ) :
            if ( i & ( 1 << j ) ) :
                temp *= primes [ j ]
        check = True
        for k in range ( N ) :
            if ( gcd ( temp , arr [ k ] ) == 1 ) :
                check = False
                break
        if ( check ) :
            ans = min ( ans , temp )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 6 , 7 , 8 , 9 , 10 ]
    N = len ( arr )
    findMinimumNumber ( arr , N )

Index/key variables: j, k
Accumulator variables: primes, temp
Iterator variables: i, j, k
Boolean variables: check
Python program:
R = 100005
arr = [ 0 for i in range ( R ) ]
def canExpress ( N ) :
    temp = N
    n = 0
    while ( N != 0 ) :
        N //= 10
        n += 1
    N = temp
    sum = 0
    while ( N != 0 ) :
        sum += pow ( N % 10 , n )
        N //= 10
    return ( sum == temp )
def precompute ( ) :
    for i in range ( 1 , R , 1 ) :
        if ( canExpress ( i ) ) :
            arr [ i ] = 1
    for i in range ( 1 , R , 1 ) :
        arr [ i ] += arr [ i - 1 ]
def countNumbers ( queries , N ) :
    precompute ( )
    for i in range ( N ) :
        L1 = queries [ i ] [ 0 ]
        R1 = queries [ i ] [ 1 ]
        print ( ( arr [ R1 ] - arr [ L1 - 1 ] ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    queries = [ [ 1 , 400 ] , [ 1 , 9 ] ]
    N = len ( queries )
    countNumbers ( queries , N )

Index/key variables: R1, i
Accumulator variables: N, n, sum
Iterator variables: i
Python program:
def sumOfNodeInAPath ( node_value ) :
    sum_of_node = 0
    while ( node_value ) :
        sum_of_node += node_value
        node_value //= 2
    print ( sum_of_node , end = " ▁ " )
def findSum ( Q ) :
    for i in range ( len ( Q ) ) :
        node_value = Q [ i ]
        sumOfNodeInAPath ( node_value )
        print ( end = " " )
arr = [ 1 , 5 , 20 , 100 ]
findSum ( arr )

Index/key variables: i
Accumulator variables: node_value, sum_of_node
Iterator variables: i
Python program:
from collections import defaultdict
def minDeletions ( arr , N ) :
    freq = defaultdict ( int )
    for i in range ( N ) :
        freq [ arr [ i ] ] += 1
    v = [ ]
    for z in freq . keys ( ) :
        v . append ( freq [ z ] )
    v . sort ( )
    size = len ( v )
    ans = N - ( v [ 0 ] * size )
    for i in range ( 1 , len ( v ) ) :
        if ( v [ i ] != v [ i - 1 ] ) :
            safe = v [ i ] * ( size - i )
            ans = min ( ans , N - safe )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 3 , 2 , 5 , 3 ]
    N = len ( arr )
    minDeletions ( arr , N )

Index/key variables: i, z
Accumulator variables: v
Iterator variables: i, z
Python program:
class Graph :
    def __init__ ( self , vertices ) :
        self . vertices = vertices
        self . adjacency_matrix = [ [ 0 for i in range ( vertices ) ] for j in range ( vertices ) ]
    def insert ( self , s , destination ) :
        self . adjacency_matrix [ s - 1 ] [ destination - 1 ] = 1
    def issink ( self , i ) :
        for j in range ( self . vertices ) :
            if self . adjacency_matrix [ i ] [ j ] == 1 :
                return False
            if self . adjacency_matrix [ j ] [ i ] == 0 and j != i :
                return False
        return True
    def eliminate ( self ) :
        i = 0
        j = 0
        while i < self . vertices and j < self . vertices :
            if self . adjacency_matrix [ i ] [ j ] == 1 :
                i += 1
            else :
                j += 1
        if i > self . vertices :
            return - 1
        elif self . issink ( i ) is False :
            return - 1
        else :
            return i
if __name__ == " _ _ main _ _ " :
    number_of_vertices = 6
    number_of_edges = 5
    g = Graph ( number_of_vertices )
    g . insert ( 1 , 6 )
    g . insert ( 2 , 3 )
    g . insert ( 2 , 4 )
    g . insert ( 4 , 3 )
    g . insert ( 5 , 3 )
    vertex = g . eliminate ( )
    if vertex >= 0 :
        print ( " Sink ▁ found ▁ at ▁ vertex ▁ % d " % ( vertex + 1 ) )
    else :
        print ( " No ▁ Sink " )

Index/key variables: i, j
Iterator variables: j
Class/struct names: Graph
Python program:
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def preorder ( root1 , root2 , lvl ) :
    if ( root1 == None or root2 == None ) :
        return
    if ( lvl % 2 == 0 ) :
        t = root1 . key
        root1 . key = root2 . key
        root2 . key = t
    preorder ( root1 . left , root2 . right , lvl + 1 )
    preorder ( root1 . right , root2 . left , lvl + 1 )
def reverseAlternate ( root ) :
    preorder ( root . left , root . right , 0 )
def printInorder ( root ) :
    if ( root == None ) :
        return
    printInorder ( root . left )
    print ( root . key , end = " ▁ " )
    printInorder ( root . right )
def newNode ( key ) :
    temp = Node ( ' ▁ ' )
    temp . left = temp . right = None
    temp . key = key
    return temp
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( ' a ' )
    root . left = newNode ( ' b ' )
    root . right = newNode ( ' c ' )
    root . left . left = newNode ( ' d ' )
    root . left . right = newNode ( ' e ' )
    root . right . left = newNode ( ' f ' )
    root . right . right = newNode ( ' g ' )
    root . left . left . left = newNode ( ' h ' )
    root . left . left . right = newNode ( ' i ' )
    root . left . right . left = newNode ( ' j ' )
    root . left . right . right = newNode ( ' k ' )
    root . right . left . left = newNode ( ' l ' )
    root . right . left . right = newNode ( ' m ' )
    root . right . right . left = newNode ( ' n ' )
    root . right . right . right = newNode ( ' o ' )
    print ( " Inorder ▁ Traversal ▁ of ▁ given ▁ tree " )
    printInorder ( root )
    reverseAlternate ( root )
    print ( " Inorder Traversal of modified tree " )
    printInorder ( root )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def inorder ( temp ) :
    if ( not temp ) :
        return
    inorder ( temp . left )
    print ( temp . data , end = " ▁ " )
    inorder ( temp . right )
def deleteDeepest ( root , d_node ) :
    q = [ ]
    q . append ( root )
    while ( len ( q ) ) :
        temp = q . pop ( 0 )
        if temp is d_node :
            temp = None
            return
        if temp . right :
            if temp . right is d_node :
                temp . right = None
                return
            else :
                q . append ( temp . right )
        if temp . left :
            if temp . left is d_node :
                temp . left = None
                return
            else :
                q . append ( temp . left )
def deletion ( root , key ) :
    if root == None :
        return None
    if root . left == None and root . right == None :
        if root . key == key :
            return None
        else :
            return root
    key_node = None
    q = [ ]
    q . append ( root )
    while ( len ( q ) ) :
        temp = q . pop ( 0 )
        if temp . data == key :
            key_node = temp
        if temp . left :
            q . append ( temp . left )
        if temp . right :
            q . append ( temp . right )
    if key_node :
        x = temp . data
        deleteDeepest ( root , temp )
        key_node . data = x
    return root
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 10 )
    root . left = Node ( 11 )
    root . left . left = Node ( 7 )
    root . left . right = Node ( 12 )
    root . right = Node ( 9 )
    root . right . left = Node ( 15 )
    root . right . right = Node ( 8 )
    print ( " The ▁ tree ▁ before ▁ the ▁ deletion : " )
    inorder ( root )
    key = 11
    root = deletion ( root , key )
    print ( )
    print ( " The ▁ tree ▁ after ▁ the ▁ deletion ; " )
    inorder ( root )

Accumulator variables: q
Class/struct names: Node
Python program:
def countSink ( n , m , edgeFrom , edgeTo ) :
    mark = [ 0 ] * ( n + 1 )
    for i in range ( m ) :
        mark [ edgeFrom [ i ] ] = 1
    count = 0
    for i in range ( 1 , n + 1 ) :
        if ( not mark [ i ] ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    n = 4
    m = 2
    edgeFrom = [ 2 , 4 ]
    edgeTo = [ 3 , 3 ]
    print ( countSink ( n , m , edgeFrom , edgeTo ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
N = 6
def subsetGraph ( C ) :
    global N
    vertices = set ( )
    for i in range ( N ) :
        vertices . add ( i )
    while ( len ( vertices ) != 0 ) :
        if ( len ( vertices ) == 1 ) :
            return 1
        someone_removed = False
        for x in vertices :
            values = set ( )
            for y in vertices :
                if ( y != x ) :
                    values . add ( C [ x ] [ y ] )
            if ( len ( values ) == 1 ) :
                vertices . remove ( x )
                someone_removed = True
                break
        if ( not someone_removed ) :
            break
    return len ( vertices )
C = [ [ 0 , 9 , 2 , 4 , 7 , 8 ] , [ 9 , 0 , 9 , 9 , 7 , 9 ] , [ 2 , 9 , 0 , 3 , 7 , 6 ] , [ 4 , 9 , 3 , 0 , 7 , 1 ] , [ 7 , 7 , 7 , 7 , 0 , 7 ] , [ 8 , 9 , 6 , 1 , 7 , 0 ] ]
print ( subsetGraph ( C ) )

Index/key variables: x, y
Accumulator variables: values, vertices
Iterator variables: i, x, y
Boolean variables: someone_removed
Python program:
class Graph :
    def __init__ ( self , V ) :
        self . V = V
        self . adj = [ [ ] for i in range ( V ) ]
    def addEdge ( self , u , v ) :
        self . adj [ u ] . append ( v )
        self . adj [ v ] . append ( u )
    def countEdges ( self ) :
        Sum = 0
        for i in range ( self . V ) :
            Sum += len ( self . adj [ i ] )
        return Sum // 2
if __name__ == ' _ _ main _ _ ' :
    V = 9
    g = Graph ( V )
    g . addEdge ( 0 , 1 )
    g . addEdge ( 0 , 7 )
    g . addEdge ( 1 , 2 )
    g . addEdge ( 1 , 7 )
    g . addEdge ( 2 , 3 )
    g . addEdge ( 2 , 8 )
    g . addEdge ( 2 , 5 )
    g . addEdge ( 3 , 4 )
    g . addEdge ( 3 , 5 )
    g . addEdge ( 4 , 5 )
    g . addEdge ( 5 , 6 )
    g . addEdge ( 6 , 7 )
    g . addEdge ( 6 , 8 )
    g . addEdge ( 7 , 8 )
    print ( g . countEdges ( ) )

Index/key variables: i, u, v
Accumulator variables: Sum
Iterator variables: i
Class/struct names: Graph
Python program:
from queue import Queue
def isBipartiteUtil ( G , src , colorArr ) :
    global V
    colorArr [ src ] = 1
    q = Queue ( )
    q . put ( src )
    while ( not q . empty ( ) ) :
        u = q . get ( )
        for v in range ( V ) :
            if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :
                colorArr [ v ] = 1 - colorArr [ u ]
                q . put ( v )
            elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :
                return False
    return True
def isBipartite ( G ) :
    global V
    colorArr = [ - 1 ] * V
    for i in range ( V ) :
        if ( colorArr [ i ] == - 1 ) :
            if ( isBipartiteUtil ( G , i , colorArr ) == False ) :
                return False
    return True
def canBeDividedinTwoCliques ( G ) :
    global V
    GC = [ [ None ] * V for i in range ( V ) ]
    for i in range ( V ) :
        for j in range ( V ) :
            GC [ i ] [ j ] = not G [ i ] [ j ] if i != j else 0
    return isBipartite ( GC )
V = 5
G = [ [ 0 , 1 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 0 , 0 ] , [ 1 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 , 0 ] ]
if canBeDividedinTwoCliques ( G ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, src, u, v
Iterator variables: i, j, v
Python program:
maxn = 25
gr = [ [ None ] * maxn for i in range ( maxn ) ]
def isCover ( V , k , E ) :
    Set = ( 1 << k ) - 1
    limit = ( 1 << V )
    vis = [ [ None ] * maxn for i in range ( maxn ) ]
    while ( Set < limit ) :
        vis = [ [ 0 ] * maxn for i in range ( maxn ) ]
        cnt = 0
        j = 1
        v = 1
        while ( j < limit ) :
            if ( Set & j ) :
                for k in range ( 1 , V + 1 ) :
                    if ( gr [ v ] [ k ] and not vis [ v ] [ k ] ) :
                        vis [ v ] [ k ] = 1
                        vis [ k ] [ v ] = 1
                        cnt += 1
            j = j << 1
            v += 1
        if ( cnt == E ) :
            return True
        c = Set & - Set
        r = Set + c
        Set = ( ( ( r ^ Set ) >> 2 ) // c ) | r
    return False
def findMinCover ( n , m ) :
    left = 1
    right = n
    while ( right > left ) :
        mid = ( left + right ) >> 1
        if ( isCover ( n , mid , m ) == False ) :
            left = mid + 1
        else :
            right = mid
    return left
def insertEdge ( u , v ) :
    gr [ u ] [ v ] = 1
    gr [ v ] [ u ] = 1
V = 6
E = 6
insertEdge ( 1 , 2 )
insertEdge ( 2 , 3 )
insertEdge ( 1 , 3 )
insertEdge ( 1 , 4 )
insertEdge ( 1 , 5 )
insertEdge ( 1 , 6 )
print ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " , findMinCover ( V , E ) )
gr = [ [ 0 ] * maxn for i in range ( maxn ) ]
V = 6
E = 7
insertEdge ( 1 , 2 )
insertEdge ( 1 , 3 )
insertEdge ( 2 , 3 )
insertEdge ( 2 , 4 )
insertEdge ( 3 , 5 )
insertEdge ( 4 , 5 )
insertEdge ( 4 , 6 )
print ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " , findMinCover ( V , E ) )

Index/key variables: k, u, v
Accumulator variables: cnt
Iterator variables: k
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def MorrisTraversal ( root ) :
    curr = root
    while curr :
        if curr . left is None :
            print ( curr . data , end = " ▁ " )
            curr = curr . right
        else :
            prev = curr . left
            while prev . right is not None and prev . right is not curr :
                prev = prev . right
            if prev . right is curr :
                prev . right = None
                curr = curr . right
            else :
                print ( curr . data , end = " ▁ " )
                prev . right = curr
                curr = curr . left
def preorfer ( root ) :
    if root :
        print ( root . data , end = " ▁ " )
        preorfer ( root . left )
        preorfer ( root . right )
root = Node ( 1 )
root . left = Node ( 2 )
root . right = Node ( 3 )
root . left . left = Node ( 4 )
root . left . right = Node ( 5 )
root . right . left = Node ( 6 )
root . right . right = Node ( 7 )
root . left . left . left = Node ( 8 )
root . left . left . right = Node ( 9 )
root . left . right . left = Node ( 10 )
root . left . right . right = Node ( 11 )
MorrisTraversal ( root )
print ( " " )
preorfer ( root )

Class/struct names: Node
Python program:
def addEdge ( adj , u , v ) :
    adj [ u ] . append ( v )
def findSum ( adj , V ) :
    sum = 0
    for u in range ( V ) :
        sum += len ( adj [ u ] )
    return sum
if __name__ == ' _ _ main _ _ ' :
    V = 4
    adj = [ [ ] for i in range ( V ) ]
    addEdge ( adj , 0 , 2 )
    addEdge ( adj , 0 , 3 )
    addEdge ( adj , 1 , 3 )
    addEdge ( adj , 2 , 3 )
    print ( " Sum ▁ of ▁ dependencies ▁ is " , findSum ( adj , V ) )

Index/key variables: u
Accumulator variables: sum
Iterator variables: u
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def iterativePreorder ( root ) :
    if root is None :
        return
    nodeStack = [ ]
    nodeStack . append ( root )
    while ( len ( nodeStack ) > 0 ) :
        node = nodeStack . pop ( )
        print ( node . data , end = " ▁ " )
        if node . right is not None :
            nodeStack . append ( node . right )
        if node . left is not None :
            nodeStack . append ( node . left )
root = Node ( 10 )
root . left = Node ( 8 )
root . right = Node ( 2 )
root . left . left = Node ( 3 )
root . left . right = Node ( 5 )
root . right . left = Node ( 2 )
iterativePreorder ( root )

Accumulator variables: nodeStack
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data = 0 ) :
        self . data = data
        self . left = None
        self . right = None
def preorderIterative ( root ) :
    if ( root == None ) :
        return
    st = [ ]
    curr = root
    while ( len ( st ) or curr != None ) :
        while ( curr != None ) :
            print ( curr . data , end = " ▁ " )
            if ( curr . right != None ) :
                st . append ( curr . right )
            curr = curr . left
        if ( len ( st ) > 0 ) :
            curr = st [ - 1 ]
            st . pop ( )
root = Node ( 10 )
root . left = Node ( 20 )
root . right = Node ( 30 )
root . left . left = Node ( 40 )
root . left . left . left = Node ( 70 )
root . left . right = Node ( 50 )
root . right . left = Node ( 60 )
root . left . left . right = Node ( 80 )
preorderIterative ( root )

Accumulator variables: st
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
        self . flag = 0
def push ( head_ref , new_data ) :
    new_node = Node ( ) ;
    new_node . data = new_data ;
    new_node . flag = 0 ;
    new_node . next = ( head_ref ) ;
    ( head_ref ) = new_node ;
    return head_ref
def detectLoop ( h ) :
    while ( h != None ) :
        if ( h . flag == 1 ) :
            return True ;
        h . flag = 1 ;
        h = h . next ;
    return False ;
if __name__ == ' _ _ main _ _ ' :
    head = None ;
    head = push ( head , 20 ) ;
    head = push ( head , 4 ) ;
    head = push ( head , 15 ) ;
    head = push ( head , 10 )
    head . next . next . next . next = head ;
    if ( detectLoop ( head ) ) :
        print ( " Loop ▁ found " )
    else :
        print ( " No ▁ Loop " )

Class/struct names: Node