dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
N = 1000
adj = [ [ ] for i in range ( N ) ]
def dfsUtil ( u , node , visited , road_used , parent , it ) :
    c = 0
    for i in range ( node ) :
        if ( visited [ i ] ) :
            c += 1
    if ( c == node ) :
        return
    visited [ u ] = True
    road_used . append ( [ parent , u ] )
    print ( u , end = " ▁ " )
    for x in adj [ u ] :
        if ( not visited [ x ] ) :
            dfsUtil ( x , node , visited , road_used , u , it + 1 )
    for y in road_used :
        if ( y [ 1 ] == u ) :
            dfsUtil ( y [ 0 ] , node , visited , road_used , u , it + 1 )
def dfs ( node ) :
    visited = [ False for i in range ( node ) ]
    road_used = [ ]
    for i in range ( node ) :
        visited [ i ] = False
    dfsUtil ( 0 , node , visited , road_used , - 1 , 0 )
def insertEdge ( u , v ) :
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
if __name__ == ' _ _ main _ _ ' :
    node = 11
    edge = 13
    insertEdge ( 0 , 1 )
    insertEdge ( 0 , 2 )
    insertEdge ( 1 , 5 )
    insertEdge ( 1 , 6 )
    insertEdge ( 2 , 4 )
    insertEdge ( 2 , 9 )
    insertEdge ( 6 , 7 )
    insertEdge ( 6 , 8 )
    insertEdge ( 7 , 8 )
    insertEdge ( 2 , 3 )
    insertEdge ( 3 , 9 )
    insertEdge ( 3 , 10 )
    insertEdge ( 9 , 10 )
    dfs ( node )

Index/key variables: i, u, v, x
Accumulator variables: c
Iterator variables: i, x, y
Python program:
def swap ( string , i , j ) :
    return ( string [ : i ] + string [ j ] + string [ i + 1 : j ] + string [ i ] + string [ j + 1 : ] )
def findMaximumNum ( string , k , maxm ) :
    if k == 0 :
        return
    n = len ( string )
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            if string [ i ] < string [ j ] :
                string = swap ( string , i , j )
                if string > maxm [ 0 ] :
                    maxm [ 0 ] = string
                findMaximumNum ( string , k - 1 , maxm )
                string = swap ( string , i , j )
if __name__ == " _ _ main _ _ " :
    string = "129814999"
    k = 4
    maxm = [ string ]
    findMaximumNum ( string , k , maxm )
    print ( maxm [ 0 ] )

Index/key variables: i, j
Iterator variables: i, j
Python program:
allPaths = [ ]
def findPaths ( maze , m , n ) :
    path = [ 0 for d in range ( m + n - 1 ) ]
    findPathsUtil ( maze , m , n , 0 , 0 , path , 0 )
def findPathsUtil ( maze , m , n , i , j , path , indx ) :
    global allPaths
    if i == m - 1 :
        for k in range ( j , n ) :
            path [ indx + k - j ] = maze [ i ] [ k ]
        print ( path )
        allPaths . append ( path )
        return
    if j == n - 1 :
        for k in range ( i , m ) :
            path [ indx + k - i ] = maze [ k ] [ j ]
        print ( path )
        allPaths . append ( path )
        return
    path [ indx ] = maze [ i ] [ j ]
    findPathsUtil ( maze , m , n , i + 1 , j , path , indx + 1 )
    findPathsUtil ( maze , m , n , i , j + 1 , path , indx + 1 )
if __name__ == ' _ _ main _ _ ' :
    maze = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    findPaths ( maze , 3 , 3 )

Index/key variables: i, indx, j, k
Iterator variables: k
Python program:
def chkPair ( A , size , x ) :
    for i in range ( 0 , size - 1 ) :
        for j in range ( i + 1 , size ) :
            if ( A [ i ] + A [ j ] == x ) :
                print ( " Pair ▁ with ▁ a ▁ given ▁ sum ▁ " , x , " ▁ is ▁ ( " , A [ i ] , " , ▁ " , A [ j ] , " ) " )
                return True
    return False
A = [ 0 , - 1 , 2 , - 3 , 1 ]
x = - 2
size = len ( A )
if ( chkPair ( A , size , x ) ) :
    print ( " Valid ▁ pair ▁ exists " )
else :
    print ( " No ▁ valid ▁ pair ▁ exists ▁ for ▁ " , x )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def mergeSort ( arr , array_size ) :
    temp = [ 0 for i in range ( array_size ) ]
    return _mergeSort ( arr , temp , 0 , array_size - 1 )
def _mergeSort ( arr , temp , left , right ) :
    mid , inv_count = 0 , 0
    if ( right > left ) :
        mid = ( right + left ) // 2
        inv_count = _mergeSort ( arr , temp , left , mid )
        inv_count += _mergeSort ( arr , temp , mid + 1 , right )
        inv_count += merge ( arr , temp , left , mid + 1 , right )
    return inv_count
def merge ( arr , temp , left , mid , right ) :
    inv_count = 0
    i = left
    j = mid
    k = left
    while ( ( i <= mid - 1 ) and ( j <= right ) ) :
        if ( arr [ i ] > 2 * arr [ j ] ) :
            inv_count += ( mid - i )
            j += 1
        else :
            i += 1
    i = left
    j = mid
    k = left
    while ( ( i <= mid - 1 ) and ( j <= right ) ) :
        if ( arr [ i ] <= arr [ j ] ) :
            temp [ k ] = arr [ i ]
            i , k = i + 1 , k + 1
        else :
            temp [ k ] = arr [ j ]
            k , j = k + 1 , j + 1
    while ( i <= mid - 1 ) :
        temp [ k ] = arr [ i ]
        i , k = i + 1 , k + 1
    while ( j <= right ) :
        temp [ k ] = arr [ j ]
        j , k = j + 1 , k + 1
    for i in range ( left , right + 1 ) :
        arr [ i ] = temp [ i ]
    return inv_count
arr = [ 1 , 20 , 6 , 4 , 5 ]
n = len ( arr )
print ( mergeSort ( arr , n ) )

Index/key variables: i, j, k
Accumulator variables: inv_count
Iterator variables: i
Python program:
N = 100005
lazy = [ 0 ] * ( 4 * N ) ;
se = set ( )
def update ( x , y , value , id , l , r ) :
    if ( x >= r or l >= y ) :
        return ;
    if ( x <= l and r <= y ) :
        lazy [ id ] = value ;
        return ;
    mid = ( l + r ) // 2 ;
    if ( lazy [ id ] ) :
        lazy [ 2 * id ] = lazy [ 2 * id + 1 ] = lazy [ id ] ;
    lazy [ id ] = 0 ;
    update ( x , y , value , 2 * id , l , mid ) ;
    update ( x , y , value , 2 * id + 1 , mid , r ) ;
def query ( id , l , r ) :
    if ( lazy [ id ] ) :
        se . add ( lazy [ id ] ) ;
        return ;
    if ( r - l < 2 ) :
        return ;
    mid = ( l + r ) // 2 ;
    query ( 2 * id , l , mid ) ;
    query ( 2 * id + 1 , mid , r ) ;
if __name__ == " _ _ main _ _ " :
    n = 5 ; q = 3 ;
    update ( 1 , 4 , 1 , 1 , 0 , n ) ;
    update ( 0 , 2 , 2 , 1 , 0 , n ) ;
    update ( 3 , 4 , 3 , 1 , 0 , n ) ;
    query ( 1 , 0 , n ) ;
    print ( len ( se ) ) ;

Index/key variables: id
Python program:
def shuffleArray ( a , n ) :
    i , q , k = 0 , 1 , n
    while ( i < n ) :
        j = k
        while ( j > i + q ) :
            a [ j - 1 ] , a [ j ] = a [ j ] , a [ j - 1 ]
            j -= 1
        i += 1
        k += 1
        q += 1
a = [ 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 ]
n = len ( a )
shuffleArray ( a , int ( n / 2 ) )
for i in range ( 0 , n ) :
    print ( a [ i ] , end = " ▁ " )

Index/key variables: i, j
Accumulator variables: k, q
Iterator variables: i
Python program:
def isFeasible ( mid , arr , n , k ) :
    pos = arr [ 0 ]
    elements = 1
    for i in range ( 1 , n , 1 ) :
        if ( arr [ i ] - pos >= mid ) :
            pos = arr [ i ]
            elements += 1
            if ( elements == k ) :
                return True
    return 0
def largestMinDist ( arr , n , k ) :
    arr . sort ( reverse = False )
    res = - 1
    left = 1
    right = arr [ n - 1 ]
    while ( left < right ) :
        mid = ( left + right ) / 2
        if ( isFeasible ( mid , arr , n , k ) ) :
            res = max ( res , mid )
            left = mid + 1
        else :
            right = mid
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 8 , 4 , 9 ]
    n = len ( arr )
    k = 3
    print ( largestMinDist ( arr , n , k ) )

Index/key variables: i
Accumulator variables: elements
Iterator variables: i
Python program:
def findFrequency ( arr , n ) :
    mp = { }
    for i in range ( n ) :
        if arr [ i ] not in mp :
            mp [ arr [ i ] ] = 0
        mp [ arr [ i ] ] += 1
    for i in mp :
        print ( " Element " , i , " occurs " , mp [ i ] , " times " )
arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ]
n = len ( arr )
findFrequency ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 100
class Node :
    def __init__ ( self , data ) :
        self . left = None
        self . right = None
        self . data = data
def newNode ( item ) :
    temp = Node ( item )
    return temp
def storeAlternate ( root , arr , index , l ) :
    if ( root == None ) :
        return index ;
    index = storeAlternate ( root . left , arr , index , l + 1 ) ;
    if ( l % 2 != 0 ) :
        arr [ index ] = root . data ;
        index += 1 ;
    index = storeAlternate ( root . right , arr , index , l + 1 ) ;
    return index
def modifyTree ( root , arr , index , l ) :
    if ( root == None ) :
        return index ;
    index = modifyTree ( root . left , arr , index , l + 1 ) ;
    if ( l % 2 != 0 ) :
        root . data = arr [ index ] ;
        index += 1 ;
    index = modifyTree ( root . right , arr , index , l + 1 ) ;
    return index
def reverse ( arr , n ) :
    l = 0
    r = n - 1 ;
    while ( l < r ) :
        arr [ l ] , arr [ r ] = ( arr [ r ] , arr [ l ] ) ;
        l += 1
        r -= 1
def reverseAlternate ( root ) :
    arr = [ 0 for i in range ( MAX ) ]
    index = 0 ;
    index = storeAlternate ( root , arr , index , 0 ) ;
    reverse ( arr , index ) ;
    index = 0 ;
    index = modifyTree ( root , arr , index , 0 ) ;
def printInorder ( root ) :
    if ( root == None ) :
        return ;
    printInorder ( root . left ) ;
    print ( root . data , end = ' ▁ ' )
    printInorder ( root . right ) ;
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 ) ;

Index/key variables: index, l, r
Class/struct names: Node
Python program:
def findSquareSum ( Coordinates , N ) :
    xq , yq = 0 , 0
    xs , ys = 0 , 0
    res = 0
    for i in range ( N ) :
        a = Coordinates [ i ] [ 0 ]
        b = Coordinates [ i ] [ 1 ]
        res += xq
        res -= 2 * xs * a
        res += i * ( a * a )
        xq += a * a
        xs += a
        res += yq
        res -= 2 * ys * b
        res += i * b * b
        yq += b * b
        ys += b
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 1 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ - 1 , 1 ] ]
    N = len ( arr )
    findSquareSum ( arr , N )

Index/key variables: i
Accumulator variables: res, xq, xs, yq, ys
Iterator variables: i
Python program:
def getPointsIns ( x1 , y1 , radius , x2 , y2 , points ) :
    for point in points :
        condOne = ( point [ 1 ] - y2 ) * ( x2 - x1 ) - ( y2 - y1 ) * ( point [ 0 ] - x2 ) >= 0
        condTwo = radius >= ( ( y1 - point [ 1 ] ) ** 2 + ( x1 - point [ 0 ] ) ** 2 ) ** ( 0.5 )
        if condOne and condTwo :
            ans += 1
    return ans
X = 0
Y = 0
R = 5
P = 5
Q = 0
arr = [ [ 2 , 3 ] , [ 5 , 6 ] , [ - 1 , 4 ] , [ 5 , 5 ] ]
print ( getPointsIns ( X , Y , R , P , Q , arr ) )

Accumulator variables: ans
Iterator variables: point
Python program:
def cntPairs ( points , n , K ) :
    ans = 0
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            dist = 0
            for k in range ( K ) :
                temp = ( points [ i ] [ k ] - points [ j ] [ k ] )
                dist += temp * temp
            if ( ( ( dist ) ** ( 1 / 2 ) ) * ( ( dist ) ** ( 1 / 2 ) ) == dist ) :
                ans += 1
    print ( ans )
K = 2
points = [ [ 1 , 2 ] , [ 5 , 5 ] , [ - 2 , 8 ] ]
n = len ( points )
cntPairs ( points , n , K )

Index/key variables: i, j, k
Accumulator variables: ans, dist
Iterator variables: i, j, k
Python program:
def countOdd ( n ) :
    coun = 0
    i = n - 2
    while ( i >= 1 ) :
        if ( i & 1 ) :
            m = int ( ( n - i ) / 2 )
            j = int ( ( i * ( i + 1 ) ) / 2 )
            coun += j * m
        else :
            m = int ( ( ( n - 1 ) - i ) / 2 )
            j = int ( ( i * ( i + 1 ) ) / 2 )
            coun += j * m
        i -= 1
    return coun
def countEven ( n ) :
    coun = 0
    i = n - 2
    while ( i >= 1 ) :
        if ( i & 1 ) :
            m = int ( ( ( n - 1 ) - i ) / 2 )
            j = int ( ( i * ( i + 1 ) ) / 2 )
            coun += j * m
        else :
            m = int ( ( n - i ) / 2 )
            j = ( i * ( i + 1 ) ) // 2
            coun += j * m
    return coun
if __name__ == ' _ _ main _ _ ' :
    n = 5
    if ( n & 1 ) :
        print ( countOdd ( n ) )
    else :
        print ( countEven ( n ) )

Accumulator variables: coun, i
Python program:
class contact :
    def __init__ ( self , field1 , field2 , field3 ) :
        self . field1 = field1
        self . field2 = field2
        self . field3 = field3
def buildGraph ( arr , n , mat ) :
    for i in range ( n ) :
        for j in range ( n ) :
            mat [ i ] [ j ] = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ i ] . field1 == arr [ j ] . field1 or arr [ i ] . field1 == arr [ j ] . field2 or arr [ i ] . field1 == arr [ j ] . field3 or arr [ i ] . field2 == arr [ j ] . field1 or arr [ i ] . field2 == arr [ j ] . field2 or arr [ i ] . field2 == arr [ j ] . field3 or arr [ i ] . field3 == arr [ j ] . field1 or arr [ i ] . field3 == arr [ j ] . field2 or arr [ i ] . field3 == arr [ j ] . field3 ) :
                mat [ i ] [ j ] = 1
                mat [ j ] [ i ] = 1
                break
def DFSvisit ( i , mat , visited , sol , n ) :
    visited [ i ] = True
    sol . append ( i )
    for j in range ( n ) :
        if ( mat [ i ] [ j ] and not visited [ j ] ) :
            DFSvisit ( j , mat , visited , sol , n )
def findSameContacts ( arr , n ) :
    sol = [ ]
    mat = [ [ None ] * n for i in range ( n ) ]
    visited = [ 0 ] * n
    buildGraph ( arr , n , mat )
    for i in range ( n ) :
        if ( not visited [ i ] ) :
            DFSvisit ( i , mat , visited , sol , n )
            sol . append ( - 1 )
    for i in range ( len ( sol ) ) :
        if ( sol [ i ] == - 1 ) :
            print ( )
        else :
            print ( sol [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ contact ( " Gaurav " , " gaurav @ gmail . com " , " gaurav @ gfgQA . com " ) , contact ( " Lucky " , " lucky @ gmail . com " , " + 1234567" ) , contact ( " gaurav123" , " + 5412312" , " gaurav123 @ skype . com " ) , contact ( " gaurav1993" , " + 5412312" , " gaurav @ gfgQA . com " ) , contact ( " raja " , " + 2231210" , " raja @ gfg . com " ) , contact ( " bahubali " , " + 878312" , " raja " ) ]
    n = len ( arr )
    findSameContacts ( arr , n )

Index/key variables: i, j
Accumulator variables: sol
Iterator variables: i, j
Class/struct names: contact
Python program:
def binomialCoeff ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( k ) :
        res *= ( n - i )
        res //= ( i + 1 )
    return res
def countPaths ( x1 , y1 , x2 , y2 ) :
    m = abs ( x1 - x2 )
    n = abs ( y1 - y2 )
    return ( binomialCoeff ( m + n , n ) )
x1 , y1 , x2 , y2 = 2 , 3 , 4 , 5
print ( countPaths ( x1 , y1 , x2 , y2 ) )

Accumulator variables: res
Iterator variables: i
Python program:
import sys
def maxLines ( n , x1 , y1 , x2 , y2 ) :
    s = [ ] ;
    slope = sys . maxsize ;
    for i in range ( n ) :
        if ( x1 [ i ] == x2 [ i ] ) :
            slope = sys . maxsize ;
        else :
            slope = ( y2 [ i ] - y1 [ i ] ) * 1.0 / ( x2 [ i ] - x1 [ i ] ) * 1.0 ;
        s . append ( slope ) ;
    return len ( s ) ;
n = 2 ;
x1 = [ 1 , 2 ] ;
y1 = [ 1 , 2 ] ;
x2 = [ 2 , 4 ] ;
y2 = [ 2 , 10 ] ;
print ( maxLines ( n , x1 , y1 , x2 , y2 ) ) ;

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def parallel ( n , a ) :
    x = True ;
    y = True ;
    for i in range ( n - 1 ) :
        if ( a [ i ] [ 0 ] != a [ i + 1 ] [ 0 ] ) :
            x = False ;
        if ( a [ i ] [ 1 ] != a [ i + 1 ] [ 1 ] ) :
            y = False ;
    if ( x ) :
        print ( " Parallel ▁ to ▁ Y ▁ Axis " ) ;
    elif ( y ) :
        print ( " Parallel ▁ to ▁ X ▁ Axis " ) ;
    else :
        print ( " Not ▁ Parallel ▁ to ▁ X ▁ and ▁ Y ▁ Axis " ) ;
a = [ [ 1 , 2 ] , [ 1 , 4 ] , [ 1 , 6 ] , [ 1 , 0 ] ] ;
n = len ( a ) ;
parallel ( n , a ) ;

Index/key variables: i
Iterator variables: i
Boolean variables: x, y
Python program:
def overlappingArea ( l1 , r1 , l2 , r2 ) :
    x = 0
    y = 1
    area1 = abs ( l1 [ x ] - r1 [ x ] ) * abs ( l1 [ y ] - r1 [ y ] )
    area2 = abs ( l2 [ x ] - r2 [ x ] ) * abs ( l2 [ y ] - r2 [ y ] )
    x_dist = ( min ( r1 [ x ] , r2 [ x ] ) - max ( l1 [ x ] , l2 [ x ] ) )
    y_dist = ( min ( r1 [ y ] , r2 [ y ] ) - max ( l1 [ y ] , l2 [ y ] ) )
    areaI = 0
    if x_dist > 0 and y_dist > 0 :
        areaI = x_dist * y_dist
    return ( area1 + area2 - areaI )
l1 = [ 2 , 2 ]
r1 = [ 5 , 7 ]
l2 = [ 3 , 4 ]
r2 = [ 6 , 9 ]
print ( overlappingArea ( l1 , r1 , l2 , r2 ) )

Index/key variables: x, y
Python program:
M = 3 ;
N = 3 ;
def contribution_height ( current , previous ) :
    return abs ( current - previous ) ;
def surfaceArea ( A ) :
    ans = 0 ;
    for i in range ( N ) :
        for j in range ( M ) :
            up = 0 ;
            left = 0 ;
            if ( i > 0 ) :
                up = A [ i - 1 ] [ j ] ;
            if ( j > 0 ) :
                left = A [ i ] [ j - 1 ] ;
            ans += contribution_height ( A [ i ] [ j ] , up ) + contribution_height ( A [ i ] [ j ] , left ) ;
            if ( i == N - 1 ) :
                ans += A [ i ] [ j ] ;
            if ( j == M - 1 ) :
                ans += A [ i ] [ j ] ;
    ans += N * M * 2 ;
    return ans ;
A = [ [ 1 , 3 , 4 ] , [ 2 , 2 , 3 ] , [ 1 , 2 , 4 ] ] ;
print ( surfaceArea ( A ) ) ;

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def printSet ( x , y ) :
    arr = [ ]
    for i in range ( min ( x , y ) + 1 ) :
        pq = [ i , min ( x , y ) - i ]
        arr . append ( pq )
    for it in arr :
        print ( it [ 0 ] , it [ 1 ] )
if __name__ == " _ _ main _ _ " :
    x = 4
    y = 4
    printSet ( x , y )

Accumulator variables: arr
Iterator variables: i, it
Python program:
import math
def countRect ( n ) :
    ans = 0
    for length in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) :
        height = length
        while ( height * length <= n ) :
            ans += 1
            height += 1
    return ans
n = 5
print ( countRect ( n ) )

Accumulator variables: ans, height
Iterator variables: length
Python program:
def bestApproximate ( x , y , n ) :
    sum_x = 0
    sum_y = 0
    sum_xy = 0
    sum_x2 = 0
    for i in range ( 0 , n ) :
        sum_x += x [ i ]
        sum_y += y [ i ]
        sum_xy += x [ i ] * y [ i ]
        sum_x2 += pow ( x [ i ] , 2 )
    m = ( float ) ( ( n * sum_xy - sum_x * sum_y ) / ( n * sum_x2 - pow ( sum_x , 2 ) ) ) ;
    c = ( float ) ( sum_y - m * sum_x ) / n ;
    print ( " m ▁ = ▁ " , m ) ;
    print ( " c ▁ = ▁ " , c ) ;
x = [ 1 , 2 , 3 , 4 , 5 ]
y = [ 14 , 27 , 40 , 55 , 68 ]
n = len ( x )
bestApproximate ( x , y , n )

Index/key variables: i
Accumulator variables: sum_x, sum_x2, sum_xy, sum_y
Iterator variables: i
Python program:
size = 4
def checkStar ( mat ) :
    global size
    vertexD1 = 0
    vertexDn_1 = 0
    if ( size == 1 ) :
        return ( mat [ 0 ] [ 0 ] == 0 )
    if ( size == 2 ) :
        return ( mat [ 0 ] [ 0 ] == 0 and mat [ 0 ] [ 1 ] == 1 and mat [ 1 ] [ 0 ] == 1 and mat [ 1 ] [ 1 ] == 0 )
    for i in range ( 0 , size ) :
        degreeI = 0
        for j in range ( 0 , size ) :
            if ( mat [ i ] [ j ] ) :
                degreeI = degreeI + 1
        if ( degreeI == 1 ) :
            vertexD1 = vertexD1 + 1
        elif ( degreeI == size - 1 ) :
            vertexDn_1 = vertexDn_1 + 1
    return ( vertexD1 == ( size - 1 ) and vertexDn_1 == 1 )
mat = [ [ 0 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] ]
if ( checkStar ( mat ) ) :
    print ( " Star ▁ Graph " )
else :
    print ( " Not ▁ a ▁ Star ▁ Graph " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import copy
def orientation ( a , b , c ) :
    res = ( ( b [ 1 ] - a [ 1 ] ) * ( c [ 0 ] - b [ 0 ] ) - ( c [ 1 ] - b [ 1 ] ) * ( b [ 0 ] - a [ 0 ] ) )
    if ( res == 0 ) :
        return 0 ;
    if ( res > 0 ) :
        return 1 ;
    return - 1 ;
def sqDist ( p1 , p2 ) :
    return ( ( p1 [ 0 ] - p2 [ 0 ] ) * ( p1 [ 0 ] - p2 [ 0 ] ) + ( p1 [ 1 ] - p2 [ 1 ] ) * ( p1 [ 1 ] - p2 [ 1 ] ) ) ;
def inside ( a , p ) :
    mid = [ 0 , 0 ]
    n = len ( a )
    p [ 0 ] *= n ;
    p [ 1 ] *= n ;
    for i in range ( n ) :
        mid [ 0 ] += a [ i ] [ 0 ] ;
        mid [ 1 ] += a [ i ] [ 1 ] ;
        a [ i ] [ 0 ] *= n ;
        a [ i ] [ 1 ] *= n ;
    for i in range ( n ) :
        j = ( i + 1 ) % n ;
        x1 = a [ i ] [ 0 ]
        x2 = a [ j ] [ 0 ]
        y1 = a [ i ] [ 1 ]
        y2 = a [ j ] [ 1 ]
        a1 = y1 - y2 ;
        b1 = x2 - x1 ;
        c1 = x1 * y2 - y1 * x2 ;
        for_mid = a1 * mid [ 0 ] + b1 * mid [ 1 ] + c1 ;
        for_p = a1 * p [ 0 ] + b1 * p [ 1 ] + c1 ;
        if ( for_mid * for_p < 0 ) :
            return False ;
    return True ;
def addPoint ( a , p ) :
    arr = copy . deepcopy ( a )
    prr = p . copy ( )
    if ( inside ( arr , prr ) ) :
        return ;
    ind = 0 ;
    n = len ( a )
    for i in range ( 1 , n ) :
        if ( sqDist ( p , a [ i ] ) < sqDist ( p , a [ ind ] ) ) :
            ind = i
    up = ind ;
    while ( orientation ( p , a [ up ] , a [ ( up + 1 ) % n ] ) >= 0 ) :
        up = ( up + 1 ) % n ;
    low = ind ;
    while ( orientation ( p , a [ low ] , a [ ( n + low - 1 ) % n ] ) <= 0 ) :
        low = ( n + low - 1 ) % n
    ret = [ ]
    curr = up ;
    ret . append ( a [ curr ] ) ;
    while ( curr != low ) :
        curr = ( curr + 1 ) % n ;
        ret . append ( a [ curr ] ) ;
    ret . append ( p ) ;
    a . clear ( ) ;
    for i in range ( len ( ret ) ) :
        a . append ( ret [ i ] ) ;
if __name__ == " _ _ main _ _ " :
    a = [ ]
    a . append ( [ 0 , 0 ] ) ;
    a . append ( [ 3 , - 1 ] ) ;
    a . append ( [ 4 , 5 ] ) ;
    a . append ( [ - 1 , 4 ] ) ;
    n = len ( a )
    p = [ 100 , 100 ]
    addPoint ( a , p ) ;
    for e in a :
        print ( " ( " , e [ 0 ] , " , ▁ " , e [ 1 ] , " ) ▁ " , end = " ▁ " )

Index/key variables: curr, i, ind, j, low, up
Accumulator variables: a, ret
Iterator variables: e, i