dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
R = 3
C = 3
x = [ 0 , 1 , 1 , - 1 , 1 , 0 , - 1 , - 1 ]
y = [ 1 , 0 , 1 , 1 , - 1 , - 1 , 0 , - 1 ]
dp = [ [ 0 for i in range ( C ) ] for i in range ( R ) ]
def isvalid ( i , j ) :
    if ( i < 0 or j < 0 or i >= R or j >= C ) :
        return False
    return True
def isadjacent ( prev , curr ) :
    if ( ord ( curr ) - ord ( prev ) ) == 1 :
        return True
    return False
def getLenUtil ( mat , i , j , prev ) :
    if ( isvalid ( i , j ) == False or isadjacent ( prev , mat [ i ] [ j ] ) == False ) :
        return 0
    if ( dp [ i ] [ j ] != - 1 ) :
        return dp [ i ] [ j ]
    ans = 0
    for k in range ( 8 ) :
        ans = max ( ans , 1 + getLenUtil ( mat , i + x [ k ] , j + y [ k ] , mat [ i ] [ j ] ) )
    dp [ i ] [ j ] = ans
    return dp [ i ] [ j ]
def getLen ( mat , s ) :
    for i in range ( R ) :
        for j in range ( C ) :
            dp [ i ] [ j ] = - 1
    ans = 0
    for i in range ( R ) :
        for j in range ( C ) :
            if ( mat [ i ] [ j ] == s ) :
                for k in range ( 8 ) :
                    ans = max ( ans , 1 + getLenUtil ( mat , i + x [ k ] , j + y [ k ] , s ) ) ;
    return ans
mat = [ [ ' a ' , ' c ' , ' d ' ] , [ ' h ' , ' b ' , ' a ' ] , [ ' i ' , ' g ' , ' f ' ] ]
print ( getLen ( mat , ' a ' ) )
print ( getLen ( mat , ' e ' ) )
print ( getLen ( mat , ' b ' ) )
print ( getLen ( mat , ' f ' ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
n = 3
def findLongestFromACell ( i , j , mat , dp ) :
    if ( i < 0 or i >= n or j < 0 or j >= n ) :
        return 0
    if ( dp [ i ] [ j ] != - 1 ) :
        return dp [ i ] [ j ]
    x , y , z , w = - 1 , - 1 , - 1 , - 1
    if ( j < n - 1 and ( ( mat [ i ] [ j ] + 1 ) == mat [ i ] [ j + 1 ] ) ) :
        x = 1 + findLongestFromACell ( i , j + 1 , mat , dp )
    if ( j > 0 and ( mat [ i ] [ j ] + 1 == mat [ i ] [ j - 1 ] ) ) :
        y = 1 + findLongestFromACell ( i , j - 1 , mat , dp )
    if ( i > 0 and ( mat [ i ] [ j ] + 1 == mat [ i - 1 ] [ j ] ) ) :
        z = 1 + findLongestFromACell ( i - 1 , j , mat , dp )
    if ( i < n - 1 and ( mat [ i ] [ j ] + 1 == mat [ i + 1 ] [ j ] ) ) :
        w = 1 + findLongestFromACell ( i + 1 , j , mat , dp )
    dp [ i ] [ j ] = max ( x , max ( y , max ( z , max ( w , 1 ) ) ) )
    return dp [ i ] [ j ]
def finLongestOverAll ( mat ) :
    result = 1
    dp = [ [ - 1 for i in range ( n ) ] for i in range ( n ) ]
    for i in range ( n ) :
        for j in range ( n ) :
            if ( dp [ i ] [ j ] == - 1 ) :
                findLongestFromACell ( i , j , mat , dp )
            result = max ( result , dp [ i ] [ j ] ) ;
    return result
mat = [ [ 1 , 2 , 9 ] , [ 5 , 3 , 8 ] , [ 4 , 6 , 7 ] ]
print ( " Length ▁ of ▁ the ▁ longest ▁ path ▁ is ▁ " , finLongestOverAll ( mat ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math as mt
R = 3
C = 3
def minInitialPoints ( points ) :
    dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]
    m , n = R , C
    if points [ m - 1 ] [ n - 1 ] > 0 :
        dp [ m - 1 ] [ n - 1 ] = 1
    else :
        dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1
    for i in range ( m - 2 , - 1 , - 1 ) :
        dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )
    for i in range ( 2 , - 1 , - 1 ) :
        dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )
    for i in range ( m - 2 , - 1 , - 1 ) :
        for j in range ( n - 2 , - 1 , - 1 ) :
            min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )
            dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )
    return dp [ 0 ] [ 0 ]
points = [ [ - 2 , - 3 , 3 ] , [ - 5 , - 10 , 1 ] , [ 10 , 30 , - 5 ] ]
print ( " Minimum ▁ Initial ▁ Points ▁ Required : " , minInitialPoints ( points ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class Queue :
    def __init__ ( self ) :
        self . s1 = [ ]
        self . s2 = [ ]
    def enQueue ( self , x ) :
        while len ( self . s1 ) != 0 :
            self . s2 . append ( self . s1 [ - 1 ] )
            self . s1 . pop ( )
        self . s1 . append ( x )
        while len ( self . s2 ) != 0 :
            self . s1 . append ( self . s2 [ - 1 ] )
            self . s2 . pop ( )
    def deQueue ( self ) :
        if len ( self . s1 ) == 0 :
            print ( " Q ▁ is ▁ Empty " )
        x = self . s1 [ - 1 ]
        self . s1 . pop ( )
        return x
if __name__ == ' _ _ main _ _ ' :
    q = Queue ( )
    q . enQueue ( 1 )
    q . enQueue ( 2 )
    q . enQueue ( 3 )
    print ( q . deQueue ( ) )
    print ( q . deQueue ( ) )
    print ( q . deQueue ( ) )

Class/struct names: Queue
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def convert ( root ) :
    if ( root == None ) :
        return
    convert ( root . left )
    convert ( root . right )
    if ( root . left == None ) :
        root . left = root . right
    else :
        root . left . right = root . right
    root . right = None
def downRightTraversal ( root ) :
    if ( root != None ) :
        print ( root . key , end = " ▁ " )
        downRightTraversal ( root . right )
        downRightTraversal ( root . left )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . right . left = newNode ( 4 )
    root . right . right = newNode ( 5 )
    root . right . left . left = newNode ( 6 )
    root . right . right . left = newNode ( 7 )
    root . right . right . right = newNode ( 8 )
    convert ( root )
    print ( " Traversal ▁ of ▁ the ▁ tree ▁ converted " , " to ▁ down - right ▁ form " )
    downRightTraversal ( root )

Class/struct names: newNode
Python program:
class node :
    def __init__ ( self , data ) :
        self . left = None
        self . right = None
        self . data = data
def toSumTree ( Node ) :
    if ( Node == None ) :
        return 0
    old_val = Node . data
    Node . data = toSumTree ( Node . left ) + toSumTree ( Node . right )
    return Node . data + old_val
def printInorder ( Node ) :
    if ( Node == None ) :
        return
    printInorder ( Node . left )
    print ( Node . data , end = " ▁ " )
    printInorder ( Node . right )
def newNode ( data ) :
    temp = node ( 0 )
    temp . data = data
    temp . left = None
    temp . right = None
    return temp
if __name__ == " _ _ main _ _ " :
    root = None
    x = 0
    root = newNode ( 10 )
    root . left = newNode ( - 2 )
    root . right = newNode ( 6 )
    root . left . left = newNode ( 8 )
    root . left . right = newNode ( - 4 )
    root . right . left = newNode ( 7 )
    root . right . right = newNode ( 5 )
    toSumTree ( root )
    print ( " Inorder ▁ Traversal ▁ of ▁ the ▁ resultant ▁ tree ▁ is : ▁ " )
    printInorder ( root )

Class/struct names: node
Python program:
def findPeakUtil ( arr , low , high , n ) :
    mid = low + ( high - low ) / 2
    mid = int ( mid )
    if ( ( mid == 0 or arr [ mid - 1 ] <= arr [ mid ] ) and ( mid == n - 1 or arr [ mid + 1 ] <= arr [ mid ] ) ) :
        return mid
    elif ( mid > 0 and arr [ mid - 1 ] > arr [ mid ] ) :
        return findPeakUtil ( arr , low , ( mid - 1 ) , n )
    else :
        return findPeakUtil ( arr , ( mid + 1 ) , high , n )
def findPeak ( arr , n ) :
    return findPeakUtil ( arr , 0 , n - 1 , n )
arr = [ 1 , 3 , 20 , 4 , 1 , 0 ]
n = len ( arr )
print ( " Index ▁ of ▁ a ▁ peak ▁ point ▁ is " , findPeak ( arr , n ) )

Index/key variables: mid
Python program:
def printRepeating ( arr , size ) :
    print ( " Repeating ▁ elements ▁ are ▁ " , end = ' ' )
    for i in range ( 0 , size ) :
        for j in range ( i + 1 , size ) :
            if arr [ i ] == arr [ j ] :
                print ( arr [ i ] , end = ' ▁ ' )
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ]
arr_size = len ( arr )
printRepeating ( arr , arr_size )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printRepeating ( arr , size ) :
    count = [ 0 ] * size
    print ( " ▁ Repeating ▁ elements ▁ are ▁ " , end = " " )
    for i in range ( 0 , size ) :
        if ( count [ arr [ i ] ] == 1 ) :
            print ( arr [ i ] , end = " ▁ " )
        else :
            count [ arr [ i ] ] = count [ arr [ i ] ] + 1
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ]
arr_size = len ( arr )
printRepeating ( arr , arr_size )

Index/key variables: i
Iterator variables: i
Python program:
import math
def printRepeating ( arr , size ) :
    S = 0 ;
    P = 1 ;
    n = size - 2
    for i in range ( 0 , size ) :
        S = S + arr [ i ]
        P = P * arr [ i ]
    S = S - n * ( n + 1 ) // 2
    P = P // fact ( n )
    D = math . sqrt ( S * S - 4 * P )
    x = ( D + S ) // 2
    y = ( S - D ) // 2
    print ( " The ▁ two ▁ Repeating ▁ elements ▁ are ▁ " , ( int ) ( x ) , " ▁ & ▁ " , ( int ) ( y ) )
def fact ( n ) :
    if ( n == 0 ) :
        return 1
    else :
        return ( n * fact ( n - 1 ) )
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ]
arr_size = len ( arr )
printRepeating ( arr , arr_size )

Index/key variables: i
Iterator variables: i
Python program:
def printRepeating ( arr , size ) :
    xor = arr [ 0 ]
    n = size - 2
    x = 0
    y = 0
    for i in range ( 1 , size ) :
        xor ^= arr [ i ]
    for i in range ( 1 , n + 1 ) :
        xor ^= i
    set_bit_no = xor & ~ ( xor - 1 )
    for i in range ( 0 , size ) :
        if ( arr [ i ] & set_bit_no ) :
            x = x ^ arr [ i ]
        else :
            y = y ^ arr [ i ]
    for i in range ( 1 , n + 1 ) :
        if ( i & set_bit_no ) :
            x = x ^ i
        else :
            y = y ^ i
    print ( " The ▁ two ▁ repeating " , " elements ▁ are " , y , x )
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ]
arr_size = len ( arr )
printRepeating ( arr , arr_size )

Index/key variables: i
Accumulator variables: xor
Iterator variables: i
Python program:
def printRepeating ( arr , size ) :
    print ( " ▁ The ▁ repeating ▁ elements ▁ are " , end = " ▁ " )
    for i in range ( 0 , size ) :
        if ( arr [ abs ( arr [ i ] ) ] > 0 ) :
            arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]
        else :
            print ( abs ( arr [ i ] ) , end = " ▁ " )
arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 1 ]
arr_size = len ( arr )
printRepeating ( arr , arr_size )

Index/key variables: i
Iterator variables: i
Python program:
def subArraySum ( arr , n , sum_ ) :
    for i in range ( n ) :
        curr_sum = arr [ i ]
        j = i + 1
        while j <= n :
            if curr_sum == sum_ :
                print ( " Sum ▁ found ▁ between " )
                print ( " indexes ▁ % ▁ d ▁ and ▁ % ▁ d " % ( i , j - 1 ) )
                return 1
            if curr_sum > sum_ or j == n :
                break
            curr_sum = curr_sum + arr [ j ]
            j += 1
    print ( " No ▁ subarray ▁ found " )
    return 0
arr = [ 15 , 2 , 4 , 8 , 9 , 5 , 10 , 23 ]
n = len ( arr )
sum_ = 23
subArraySum ( arr , n , sum_ )

Index/key variables: i, j
Iterator variables: i
Python program:
def subArraySum ( arr , n , sum_ ) :
    curr_sum = arr [ 0 ]
    start = 0
    i = 1
    while i <= n :
        while curr_sum > sum_ and start < i - 1 :
            curr_sum = curr_sum - arr [ start ]
            start += 1
        if curr_sum == sum_ :
            print ( " Sum ▁ found ▁ between ▁ indexes " )
            print ( " % ▁ d ▁ and ▁ % ▁ d " % ( start , i - 1 ) )
            return 1
        if i < n :
            curr_sum = curr_sum + arr [ i ]
        i += 1
    print ( " No ▁ subarray ▁ found " )
    return 0
arr = [ 15 , 2 , 4 , 8 , 9 , 5 , 10 , 23 ]
n = len ( arr )
sum_ = 23
subArraySum ( arr , n , sum_ )

Index/key variables: i, start
Python program:
def maximum ( a , b , c ) :
    return max ( max ( a , b ) , c )
def minimum ( a , b , c ) :
    return min ( min ( a , b ) , c )
def smallestDifferenceTriplet ( arr1 , arr2 , arr3 , n ) :
    arr1 . sort ( )
    arr2 . sort ( )
    arr3 . sort ( )
    res_min = 0 ; res_max = 0 ; res_mid = 0
    i = 0 ; j = 0 ; k = 0
    diff = 2147483647
    while ( i < n and j < n and k < n ) :
        sum = arr1 [ i ] + arr2 [ j ] + arr3 [ k ]
        max = maximum ( arr1 [ i ] , arr2 [ j ] , arr3 [ k ] )
        min = minimum ( arr1 [ i ] , arr2 [ j ] , arr3 [ k ] )
        if ( min == arr1 [ i ] ) :
            i += 1
        elif ( min == arr2 [ j ] ) :
            j += 1
        else :
            k += 1
        if ( diff > ( max - min ) ) :
            diff = max - min
            res_max = max
            res_mid = sum - ( max + min )
            res_min = min
    print ( res_max , " , " , res_mid , " , " , res_min )
arr1 = [ 5 , 2 , 8 ]
arr2 = [ 10 , 7 , 12 ]
arr3 = [ 9 , 14 , 6 ]
n = len ( arr1 )
smallestDifferenceTriplet ( arr1 , arr2 , arr3 , n )

Index/key variables: i, j, k
Python program:
def find3Numbers ( A , arr_size , sum ) :
    for i in range ( 0 , arr_size - 2 ) :
        for j in range ( i + 1 , arr_size - 1 ) :
            for k in range ( j + 1 , arr_size ) :
                if A [ i ] + A [ j ] + A [ k ] == sum :
                    print ( " Triplet ▁ is " , A [ i ] , " , ▁ " , A [ j ] , " , ▁ " , A [ k ] )
                    return True
    return False
A = [ 1 , 4 , 45 , 6 , 10 , 8 ]
sum = 22
arr_size = len ( A )
find3Numbers ( A , arr_size , sum )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def find3Numbers ( A , arr_size , sum ) :
    A . sort ( )
    for i in range ( 0 , arr_size - 2 ) :
        l = i + 1
        r = arr_size - 1
        while ( l < r ) :
            if ( A [ i ] + A [ l ] + A [ r ] == sum ) :
                print ( " Triplet ▁ is " , A [ i ] , ' , ▁ ' , A [ l ] , ' , ▁ ' , A [ r ] ) ;
                return True
            elif ( A [ i ] + A [ l ] + A [ r ] < sum ) :
                l += 1
            else :
                r -= 1
    return False
A = [ 1 , 4 , 45 , 6 , 10 , 8 ]
sum = 22
arr_size = len ( A )
find3Numbers ( A , arr_size , sum )

Index/key variables: i, l, r
Iterator variables: i
Python program:
def find3Numbers ( A , arr_size , sum ) :
    for i in range ( 0 , arr_size - 1 ) :
        s = set ( )
        curr_sum = sum - A [ i ]
        for j in range ( i + 1 , arr_size ) :
            if ( curr_sum - A [ j ] ) in s :
                print ( " Triplet ▁ is " , A [ i ] , " , ▁ " , A [ j ] , " , ▁ " , curr_sum - A [ j ] )
                return True
            s . add ( A [ j ] )
    return False
A = [ 1 , 4 , 45 , 6 , 10 , 8 ]
sum = 22
arr_size = len ( A )
find3Numbers ( A , arr_size , sum )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: i, j
Python program:
def subArray ( arr , n ) :
    for i in range ( 0 , n ) :
        for j in range ( i , n ) :
            for k in range ( i , j + 1 ) :
                print ( arr [ k ] , end = " ▁ " )
            print ( " " , end = " " )
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
print ( " All ▁ Non - empty ▁ Subarrays " )
subArray ( arr , n ) ;

Index/key variables: k
Iterator variables: i, j, k
Python program:
import math
def printSubsequences ( arr , n ) :
    opsize = math . pow ( 2 , n )
    for counter in range ( 1 , ( int ) ( opsize ) ) :
        for j in range ( 0 , n ) :
            if ( counter & ( 1 << j ) ) :
                print ( arr [ j ] , end = " ▁ " )
        print ( )
arr = [ 1 , 2 , 3 , 4 ]
n = len ( arr )
print ( " All ▁ Non - empty ▁ Subsequences " )
printSubsequences ( arr , n )

Index/key variables: j
Iterator variables: counter, j
Python program:
def productArray ( arr , n ) :
    if n == 1 :
        print ( 0 )
        return
    i , temp = 1 , 1
    prod = [ 1 for i in range ( n ) ]
    for i in range ( n ) :
        prod [ i ] = temp
        temp *= arr [ i ]
    temp = 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        prod [ i ] *= temp
        temp *= arr [ i ]
    for i in range ( n ) :
        print ( prod [ i ] , end = " ▁ " )
    return
arr = [ 10 , 3 , 5 , 6 , 2 ]
n = len ( arr )
print ( " The ▁ product ▁ array ▁ is : ▁ n " )
productArray ( arr , n )

Index/key variables: i
Accumulator variables: temp
Iterator variables: i
Python program:
def areConsecutive ( arr , n ) :
    if ( n < 1 ) :
        return False
    Min = min ( arr )
    Max = max ( arr )
    if ( Max - Min + 1 == n ) :
        visited = [ False for i in range ( n ) ]
        for i in range ( n ) :
            if ( visited [ arr [ i ] - Min ] != False ) :
                return False
            visited [ arr [ i ] - Min ] = True
        return True
    return False
arr = [ 5 , 4 , 2 , 3 , 1 , 6 ]
n = len ( arr )
if ( areConsecutive ( arr , n ) == True ) :
    print ( " Array ▁ elements ▁ are ▁ consecutive ▁ " )
else :
    print ( " Array ▁ elements ▁ are ▁ not ▁ consecutive ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def areConsecutive ( arr , n ) :
    if ( n < 1 ) :
        return False
    min = getMin ( arr , n )
    max = getMax ( arr , n )
    if ( max - min + 1 == n ) :
        for i in range ( n ) :
            if ( arr [ i ] < 0 ) :
                j = - arr [ i ] - min
            else :
                j = arr [ i ] - min
            if ( arr [ j ] > 0 ) :
                arr [ j ] = - arr [ j ]
            else :
                return False
        return True
    return False
def getMin ( arr , n ) :
    min = arr [ 0 ]
    for i in range ( 1 , n ) :
        if ( arr [ i ] < min ) :
            min = arr [ i ]
    return min
def getMax ( arr , n ) :
    max = arr [ 0 ]
    for i in range ( 1 , n ) :
        if ( arr [ i ] > max ) :
            max = arr [ i ]
    return max
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 4 , 5 , 3 , 2 , 6 ]
    n = len ( arr )
    if ( areConsecutive ( arr , n ) == True ) :
        print ( " ▁ Array ▁ elements ▁ are ▁ consecutive ▁ " )
    else :
        print ( " ▁ Array ▁ elements ▁ are ▁ not ▁ consecutive ▁ " )

Index/key variables: i, j
Iterator variables: i
Python program:
def relativeComplement ( arr1 , arr2 , n , m ) :
    i = 0
    j = 0
    while ( i < n and j < m ) :
        if ( arr1 [ i ] < arr2 [ j ] ) :
            print ( arr1 [ i ] , " ▁ " , end = " " )
            i += 1
        elif ( arr1 [ i ] > arr2 [ j ] ) :
            j += 1
        elif ( arr1 [ i ] == arr2 [ j ] ) :
            i += 1
            j += 1
    while ( i < n ) :
        print ( arr1 [ i ] , " ▁ " , end = " " )
arr1 = [ 3 , 6 , 10 , 12 , 15 ]
arr2 = [ 1 , 3 , 5 , 10 , 16 ]
n = len ( arr1 )
m = len ( arr2 )
relativeComplement ( arr1 , arr2 , n , m )

Index/key variables: i, j
Python program:
def minOps ( arr , n , k ) :
    max1 = max ( arr )
    res = 0
    for i in range ( 0 , n ) :
        if ( ( max1 - arr [ i ] ) % k != 0 ) :
            return - 1
        else :
            res += ( max1 - arr [ i ] ) / k
    return int ( res )
arr = [ 21 , 33 , 9 , 45 , 63 ]
n = len ( arr )
k = 6
print ( minOps ( arr , n , k ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def solve ( A , B , C ) :
    i = len ( A ) - 1
    j = len ( B ) - 1
    k = len ( C ) - 1
    min_diff = abs ( max ( A [ i ] , B [ j ] , C [ k ] ) - min ( A [ i ] , B [ j ] , C [ k ] ) )
    while i != - 1 and j != - 1 and k != - 1 :
        current_diff = abs ( max ( A [ i ] , B [ j ] , C [ k ] ) - min ( A [ i ] , B [ j ] , C [ k ] ) )
        if current_diff < min_diff :
            min_diff = current_diff
        max_term = max ( A [ i ] , B [ j ] , C [ k ] )
        if A [ i ] == max_term :
            i -= 1
        elif B [ j ] == max_term :
            j -= 1
        else :
            k -= 1
    return min_diff
A = [ 5 , 8 , 10 , 15 ]
B = [ 6 , 9 , 15 , 78 , 89 ]
C = [ 2 , 3 , 6 , 6 , 8 , 8 , 10 ]
print ( solve ( A , B , C ) )

Index/key variables: i, j, k
Python program:
def search ( arr , x ) :
    for index , value in enumerate ( arr ) :
        if value == x :
            return index
    return - 1
arr = [ 1 , 10 , 30 , 15 ]
x = 30
print ( x , " is ▁ present ▁ at ▁ index " , search ( arr , x ) )

Iterator variables: index, value
Python program:
def binarySearch ( arr , l , r , x ) :
    if r >= l :
        mid = l + ( r - l ) // 2
        if arr [ mid ] == x :
            return mid
        elif arr [ mid ] > x :
            return binarySearch ( arr , l , mid - 1 , x )
        else :
            return binarySearch ( arr , mid + 1 , r , x )
    else :
        return - 1
arr = [ 2 , 3 , 4 , 10 , 40 ]
x = 10
result = binarySearch ( arr , 0 , len ( arr ) - 1 , x )
if result != - 1 :
    print ( " Element ▁ is ▁ present ▁ at ▁ index ▁ % ▁ d " % result )
else :
    print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " )

Index/key variables: mid
Python program:
def binarySearch ( arr , l , r , x ) :
    while l <= r :
        mid = l + ( r - l ) // 2 ;
        if arr [ mid ] == x :
            return mid
        elif arr [ mid ] < x :
            l = mid + 1
        else :
            r = mid - 1
    return - 1
arr = [ 2 , 3 , 4 , 10 , 40 ]
x = 10
result = binarySearch ( arr , 0 , len ( arr ) - 1 , x )
if result != - 1 :
    print ( " Element ▁ is ▁ present ▁ at ▁ index ▁ % ▁ d " % result )
else :
    print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " )

Index/key variables: mid
Python program:
import math
def jumpSearch ( arr , x , n ) :
    step = math . sqrt ( n )
    prev = 0
    while arr [ int ( min ( step , n ) - 1 ) ] < x :
        prev = step
        step += math . sqrt ( n )
        if prev >= n :
            return - 1
    while arr [ int ( prev ) ] < x :
        prev += 1
        if prev == min ( step , n ) :
            return - 1
    if arr [ int ( prev ) ] == x :
        return prev
    return - 1
arr = [ 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 610 ]
x = 55
n = len ( arr )
index = jumpSearch ( arr , x , n )
print ( " Number " , x , " is ▁ at ▁ index " , " % .0f " % index )

Accumulator variables: prev, step
Python program:
def interpolationSearch ( arr , lo , hi , x ) :
    if ( lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] ) :
        pos = lo + ( ( hi - lo ) // ( arr [ hi ] - arr [ lo ] ) * ( x - arr [ lo ] ) )
        if arr [ pos ] == x :
            return pos
        if arr [ pos ] < x :
            return interpolationSearch ( arr , pos + 1 , hi , x )
        if arr [ pos ] > x :
            return interpolationSearch ( arr , lo , pos - 1 , x )
    return - 1
arr = [ 10 , 12 , 13 , 16 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 33 , 35 , 42 , 47 ]
n = len ( arr )
x = 18
index = interpolationSearch ( arr , 0 , n - 1 , x )
if index != - 1 :
    print ( " Element ▁ found ▁ at ▁ index " , index )
else :
    print ( " Element ▁ not ▁ found " )

Index/key variables: hi, lo, pos
Python program:
def countingSort ( arr , exp1 ) :
    n = len ( arr )
    output = [ 0 ] * ( n )
    count = [ 0 ] * ( 10 )
    for i in range ( 0 , n ) :
        index = ( arr [ i ] / exp1 )
        count [ int ( index % 10 ) ] += 1
    for i in range ( 1 , 10 ) :
        count [ i ] += count [ i - 1 ]
    i = n - 1
    while i >= 0 :
        index = ( arr [ i ] / exp1 )
        output [ count [ int ( index % 10 ) ] - 1 ] = arr [ i ]
        count [ int ( index % 10 ) ] -= 1
        i -= 1
    i = 0
    for i in range ( 0 , len ( arr ) ) :
        arr [ i ] = output [ i ]
def radixSort ( arr ) :
    max1 = max ( arr )
    exp = 1
    while max1 / exp > 0 :
        countingSort ( arr , exp )
        exp *= 10
arr = [ 170 , 45 , 75 , 90 , 802 , 24 , 2 , 66 ]
radixSort ( arr )
for i in range ( len ( arr ) ) :
    print ( arr [ i ] )

Index/key variables: i
Accumulator variables: exp
Iterator variables: i