dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def executeProcesses ( A , N , K ) :
    pq = [ ]
    for i in range ( N ) :
        pq . append ( A [ i ] )
    ans = 0
    pq . sort ( )
    while ( len ( pq ) > 0 and K > 0 ) :
        top = pq . pop ( )
        ans += 1
        K -= top
        top //= 2
        pq . append ( top )
        pq . sort ( )
    print ( ans )
A = [ 3 , 1 , 7 , 4 , 2 ]
K = 15
N = len ( A )
executeProcesses ( A , N , K )

Index/key variables: i
Accumulator variables: K, ans, pq, top
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
interNodes = [ ]
def newNode ( key ) :
    temp = Node ( key )
    return temp
def insertNode ( node , key ) :
    if ( node == None ) :
        return newNode ( key )
    if ( key < node . key ) :
        node . left = insertNode ( node . left , key )
    elif ( key > node . key ) :
        node . right = insertNode ( node . right , key )
    return node
def getIntermediateNodes ( root , node1 , node2 ) :
    if ( root == None ) :
        return
    getIntermediateNodes ( root . left , node1 , node2 )
    if ( root . key <= node2 and root . key >= node1 ) :
        interNodes . append ( root . key )
    getIntermediateNodes ( root . right , node1 , node2 )
def findMedian ( root , node1 , node2 ) :
    getIntermediateNodes ( root , node1 , node2 )
    nSize = len ( interNodes )
    if nSize % 2 == 1 :
        return interNodes [ int ( nSize / 2 ) ]
    else :
        return ( interNodes [ int ( ( nSize - 1 ) / 2 ) ] + interNodes [ nSize / 2 ] ) / 2
root = None
root = insertNode ( root , 8 )
insertNode ( root , 3 )
insertNode ( root , 1 )
insertNode ( root , 6 )
insertNode ( root , 4 )
insertNode ( root , 11 )
insertNode ( root , 15 )
print ( findMedian ( root , 3 , 11 ) )

Class/struct names: Node
Python program:
def computeTotient ( N , phi ) :
    for p in range ( 2 , N + 1 ) :
        if phi [ p ] == p :
            phi [ p ] = p - 1
            for i in range ( 2 * p , N + 1 , p ) :
                phi [ i ] = ( phi [ i ] // p ) * ( p - 1 )
def countPairs ( N ) :
    cnt_type1 = 0
    cnt_type2 = 0
    half_N = N // 2
    cnt_type1 = ( half_N * ( half_N - 1 ) ) // 2
    phi = [ 0 for i in range ( N + 1 ) ]
    for i in range ( 1 , N + 1 ) :
        phi [ i ] = i
    computeTotient ( N , phi )
    for i in range ( ( N // 2 ) + 1 , N + 1 ) :
        cnt_type2 += ( i - phi [ i ] - 1 )
    print ( cnt_type1 + cnt_type2 )
if __name__ == ' _ _ main _ _ ' :
    N = 6
    countPairs ( N )

Index/key variables: i, p
Accumulator variables: cnt_type2
Iterator variables: i, p
Python program:
ans = 10 ** 8
mini = 10 ** 8
def findClosestTarget ( i , curr , B , M , K ) :
    global ans , mini
    if ( abs ( curr - K ) < mini ) :
        mini = abs ( curr - K )
        ans = curr
    if ( abs ( curr - K ) == mini ) :
        ans = min ( ans , curr )
    if ( i >= M ) :
        return
    findClosestTarget ( i + 1 , curr + B [ i ] , B , M , K )
    findClosestTarget ( i + 1 , curr + 2 * B [ i ] , B , M , K )
    findClosestTarget ( i + 1 , curr , B , M , K )
def findClosest ( A , B , N , M , K ) :
    for i in range ( N ) :
        findClosestTarget ( 0 , A [ i ] , B , M , K )
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 3 ]
    B = [ 4 , 5 , 30 ]
    N = len ( A )
    M = len ( B )
    K = 18
    print ( findClosest ( A , B , N , M , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def convert ( arr ) :
    ans = 0
    for i in arr :
        ans = ( ans << 1 ) | i
    return ans
def count ( num ) :
    ans = 0
    while num :
        ans += num & 1
        num >>= 1
    return ans
def checkGoodMatrix ( mat ) :
    P = [ ]
    S = [ ]
    MR = [ ]
    MC = [ ]
    for i in range ( len ( mat ) ) :
        for j in range ( len ( mat [ 0 ] ) ) :
            if i == j :
                P . append ( mat [ i ] [ j ] )
            if i + j == len ( mat ) - 1 :
                S . append ( mat [ i ] [ j ] )
            if i == ( len ( mat ) - 1 ) // 2 :
                MR . append ( mat [ i ] [ j ] )
            if j == ( len ( mat ) - 1 ) // 2 :
                MC . append ( mat [ i ] [ j ] )
    S . reverse ( )
    P = convert ( P )
    S = convert ( S )
    MR = convert ( MR )
    MC = convert ( MC )
    setBitsPS = count ( P & S )
    setBitsMM = count ( MR & MC )
    if setBitsPS > setBitsMM :
        print ( " Yes " )
    else :
        print ( " No " )
mat = [ [ 1 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 0 , 1 , 1 ] ]
checkGoodMatrix ( mat )

Index/key variables: i, j
Accumulator variables: MC, MR, P, S, ans, num
Iterator variables: i, j
Python program:
from collections import deque
def assignValues ( Edges , n ) :
    tree = [ [ ] for i in range ( n + 1 ) ]
    for i in range ( n - 1 ) :
        u = Edges [ i ] [ 0 ]
        v = Edges [ i ] [ 1 ]
        tree [ u ] . append ( v )
        tree [ v ] . append ( u )
    visited = [ False ] * ( n + 1 )
    answer = [ 0 ] * ( n + 1 )
    K = 1
    q = deque ( )
    q . append ( 1 )
    answer [ 1 ] = K
    while ( len ( q ) > 0 ) :
        node = q . popleft ( )
        visited [ node ] = True
        K = 2 if ( answer [ node ] == 1 ) else 1
        for child in tree [ node ] :
            if ( not visited [ child ] ) :
                q . append ( child )
                answer [ child ] = K
    for i in range ( 1 , n + 1 ) :
        print ( answer [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 7
    Edges = [ [ 1 , 2 ] , [ 4 , 6 ] , [ 3 , 5 ] , [ 1 , 4 ] , [ 7 , 5 ] , [ 5 , 1 ] ]
    assignValues ( Edges , N )

Index/key variables: child, i, node, u, v
Accumulator variables: q
Iterator variables: child, i
Python program:
def numoffbt ( arr , n ) :
    maxvalue = - 2147483647
    minvalue = 2147483647
    for i in range ( n ) :
        maxvalue = max ( maxvalue , arr [ i ] )
        minvalue = min ( minvalue , arr [ i ] )
    mark = [ 0 for i in range ( maxvalue + 2 ) ]
    value = [ 0 for i in range ( maxvalue + 2 ) ]
    for i in range ( n ) :
        mark [ arr [ i ] ] = 1
        value [ arr [ i ] ] = 1
    ans = 0
    for i in range ( minvalue , maxvalue + 1 ) :
        if ( mark [ i ] != 0 ) :
            j = i + i
            while ( j <= maxvalue and j // i <= i ) :
                if ( mark [ j ] == 0 ) :
                    continue
                value [ j ] = value [ j ] + ( value [ i ] * value [ j // i ] )
                if ( i != j // i ) :
                    value [ j ] = value [ j ] + ( value [ i ] * value [ j // i ] )
                j += i
        ans += value [ i ]
    return ans
arr = [ 2 , 3 , 4 , 6 ]
n = len ( arr )
print ( numoffbt ( arr , n ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i
Python program:
import sys
limit = 100000
prime = [ True ] * ( limit + 1 )
def sieve ( ) :
    p = 2
    while ( p * p <= limit ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , limit , p ) :
                prime [ i ] = False
        p += 1
def findOperations ( arr , n ) :
    sieve ( )
    minm = sys . maxsize
    for i in range ( n ) :
        minm = min ( minm , arr [ i ] )
    val = minm
    for i in range ( n ) :
        if ( arr [ i ] == minm + 1 ) :
            val = minm - 2
            break
    cnt = 0
    for i in range ( n ) :
        D = arr [ i ] - val
        if ( D == 0 ) :
            continue
        elif ( prime [ D ] == True ) :
            cnt += 1
        elif ( D % 2 == 0 ) :
            cnt += 2
        else :
            if ( prime [ D - 2 ] == True ) :
                cnt += 2
            else :
                cnt += 3
    return cnt
arr = [ 7 , 10 , 4 , 5 ]
N = 4
print ( findOperations ( arr , N ) )

Index/key variables: D, i, p
Accumulator variables: cnt
Iterator variables: i
Python program:
def printUnique ( lis ) :
    lis . reverse ( )
    for i in lis :
        print ( i , end = " ▁ " )
def checkUnique ( string ) :
    lis = [ ]
    res = 0
    N = int ( string )
    cnt = [ 0 ] * 10
    while ( N > 0 ) :
        rem = N % 10
        cnt [ rem ] += 1
        N = N // 10
    N = int ( string )
    while ( N > 0 ) :
        rem = N % 10
        if ( cnt [ rem ] != ' visited ' ) :
            if ( cnt [ rem ] == 1 ) :
                lis . append ( rem )
        cnt [ rem ] = ' visited '
        N = N // 10
    printUnique ( lis )
def combineArray ( lis ) :
    string = " "
    for el in lis :
        el = str ( el )
        string = string + el
    checkUnique ( string )
arr = [ 122 , 474 , 612 , 932 ]
combineArray ( arr )

Index/key variables: rem
Accumulator variables: lis
Iterator variables: el, i
Python program:
def calcScore ( p , arr ) :
    ans = 0
    for i in range ( len ( arr ) ) :
        ans += ( p [ i ] & arr [ i ] )
    return ans
def getMaxUtil ( p , arr , ans , chosen , N ) :
    if len ( p ) == N :
        ans = max ( ans , calcScore ( p , arr ) )
        return ans
    for i in range ( N ) :
        if chosen [ i ] :
            continue
        chosen [ i ] = True
        p . append ( i )
        ans = getMaxUtil ( p , arr , ans , chosen , N )
        chosen [ i ] = False
        p . pop ( )
    return ans
def getMax ( arr , N ) :
    ans = 0
    chosen = [ False for i in range ( N ) ]
    p = [ ]
    res = getMaxUtil ( p , arr , ans , chosen , N )
    print ( res )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 3 , 6 ]
    N = len ( arr )
    getMax ( arr , N )

Index/key variables: i
Accumulator variables: ans, p
Iterator variables: i
Python program:
def setBitCount ( n ) :
    ans = 0
    while n :
        ans += n & 1
        n >>= 1
    return ans
def getSum ( arr ) :
    mp = { }
    ans = 0
    for i in arr :
        key = setBitCount ( i )
        mp [ key ] = [ 0 , i ]
    for i in arr :
        key = setBitCount ( i )
        mp [ key ] [ 0 ] += 1
    for i in mp :
        if mp [ i ] [ 0 ] == 1 :
            ans += mp [ i ] [ 1 ]
    print ( ans )
arr = [ 8 , 3 , 7 , 5 , 3 ]
getSum ( arr )

Index/key variables: i, key
Accumulator variables: ans, n
Iterator variables: i
Python program:
def findSplit ( arr , N ) :
    sum = [ i for i in arr ]
    for i in range ( 1 , N ) :
        sum [ i ] += sum [ i - 1 ]
    for l in range ( 1 , N - 3 ) :
        for r in range ( l + 2 , N - 1 ) :
            lsum , rsum , msum = 0 , 0 , 0
            lsum = sum [ l - 1 ]
            msum = sum [ r - 1 ] - sum [ l ]
            rsum = sum [ N - 1 ] - sum [ r ]
            if ( lsum == rsum and rsum == msum ) :
                print ( l , r )
                return
    print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ]
    N = len ( arr )
    findSplit ( arr , N )

Index/key variables: i, l, r
Iterator variables: i, l, r
Python program:
def findSplit ( arr , N ) :
    l = 1 ; r = N - 2 ;
    sum = [ 0 ] * N ;
    sum [ 0 ] = arr [ 0 ] ;
    for i in range ( 1 , N ) :
        sum [ i ] = sum [ i - 1 ] + arr [ i ] ;
    while ( l < r ) :
        lsum = sum [ l - 1 ] ;
        msum = sum [ r - 1 ] - sum [ l ] ;
        rsum = sum [ N - 1 ] - sum [ r ] ;
        if ( lsum == msum and msum == rsum ) :
            print ( l , r ) ;
            return ;
        if ( lsum < rsum ) :
            l += 1 ;
        elif ( lsum > rsum ) :
            r -= 1 ;
        else :
            l += 1 ;
            r -= 1 ;
    print ( - 1 ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 5 , 12 , 7 , 19 , 4 , 3 ] ;
    N = len ( arr ) ;
    findSplit ( arr , N ) ;

Index/key variables: i, l, r
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def countRec ( root , pcount ) :
    if ( root == None ) :
        return 0
    c = countRec ( root . left , pcount )
    c += countRec ( root . right , pcount )
    if ( root . data % 2 == 0 ) :
        c += 1
    if c % 2 != 0 :
        pcount [ 0 ] += 1
    return c
def countSubtrees ( root ) :
    count = [ 0 ]
    pcount = count
    countRec ( root , pcount )
    return count [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 2 )
    root . left = newNode ( 1 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 10 )
    root . right . left = newNode ( 8 )
    root . right . right = newNode ( 5 )
    root . left . right . left = newNode ( 6 )
    print ( " Count ▁ = ▁ " , countSubtrees ( root ) )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def leftMostNode ( node ) :
    while ( node != None and node . left != None ) :
        node = node . left
    return node
def rightMostNode ( node ) :
    while ( node != None and node . right != None ) :
        node = node . right
    return node
def findInorderRecursive ( root , x ) :
    if ( not root ) :
        return None
    if ( root == x or ( findInorderRecursive ( root . left , x ) ) or ( findInorderRecursive ( root . right , x ) ) ) :
        if findInorderRecursive ( root . right , x ) :
            temp = findInorderRecursive ( root . right , x )
        else :
            temp = findInorderRecursive ( root . left , x )
        if ( temp ) :
            if ( root . left == temp ) :
                print ( " Inorder ▁ Successor ▁ of " , x . data , end = " " )
                print ( " ▁ is " , root . data )
                return None
        return root
    return None
def inorderSuccesor ( root , x ) :
    if ( x . right != None ) :
        inorderSucc = leftMostNode ( x . right )
        print ( " Inorder ▁ Successor ▁ of " , x . data , " is " , end = " ▁ " )
        print ( inorderSucc . data )
    if ( x . right == None ) :
        f = 0
        rightMost = rightMostNode ( root )
        if ( rightMost == x ) :
            print ( " No ▁ inorder ▁ successor ! " , " Right ▁ most ▁ node . " )
        else :
            findInorderRecursive ( root , x )
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 . right = newNode ( 6 )
    inorderSuccesor ( root , root . right )
    inorderSuccesor ( root , root . left . left )
    inorderSuccesor ( root , root . right . right )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , key ) :
        self . left = None
        self . right = None
        self . val = key
root = Node ( 1 )
root . left = Node ( 2 ) ;
root . right = Node ( 3 ) ;
root . left . left = Node ( 4 ) ;

Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . data = item
        self . left = self . right = None
def findDistance ( root , x ) :
    if ( root == None ) :
        return - 1
    dist = - 1
    if ( root . data == x ) :
        return dist + 1
    else :
        dist = findDistance ( root . left , x )
        if dist >= 0 :
            return dist + 1
        else :
            dist = findDistance ( root . right , x )
            if dist >= 0 :
                return dist + 1
    return dist
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 5 )
    root . left = newNode ( 10 )
    root . right = newNode ( 15 )
    root . left . left = newNode ( 20 )
    root . left . right = newNode ( 25 )
    root . left . right . right = newNode ( 45 )
    root . right . left = newNode ( 30 )
    root . right . right = newNode ( 35 )
    print ( findDistance ( root , 45 ) )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , item , parent ) :
        self . data = item
        self . left = self . right = None
        self . parent = parent
def findRightSibling ( node , level ) :
    if ( node == None or node . parent == None ) :
        return None
    while ( node . parent . right == node or ( node . parent . right == None and node . parent . left == node ) ) :
        if ( node . parent == None ) :
            return None
        node = node . parent
        level -= 1
    node = node . parent . right
    while ( level < 0 ) :
        if ( node . left != None ) :
            node = node . left
        elif ( node . right != None ) :
            node = node . right
        else :
            break
        level += 1
    if ( level == 0 ) :
        return node
    return findRightSibling ( node , level )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 , None )
    root . left = newNode ( 2 , root )
    root . right = newNode ( 3 , root )
    root . left . left = newNode ( 4 , root . left )
    root . left . right = newNode ( 6 , root . left )
    root . left . left . left = newNode ( 7 , root . left . left )
    root . left . left . left . left = newNode ( 10 , root . left . left . left )
    root . left . right . right = newNode ( 9 , root . left . right )
    root . right . right = newNode ( 5 , root . right )
    root . right . right . right = newNode ( 8 , root . right . right )
    root . right . right . right . right = newNode ( 12 , root . right . right . right )
    res = findRightSibling ( root . left . left . left . left , 0 )
    if ( res == None ) :
        print ( " No ▁ right ▁ sibling " )
    else :
        print ( res . data )

Accumulator variables: level
Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def nextRightNode ( root , k , level , value_level ) :
    if ( root == None ) :
        return None
    if ( root . key == k ) :
        value_level [ 0 ] = level
        return None
    elif ( value_level [ 0 ] ) :
        if ( level == value_level [ 0 ] ) :
            return root
    leftNode = nextRightNode ( root . left , k , level + 1 , value_level )
    if ( leftNode ) :
        return leftNode
    return nextRightNode ( root . right , k , level + 1 , value_level )
def nextRightNodeUtil ( root , k ) :
    value_level = [ 0 ]
    return nextRightNode ( root , k , 1 , value_level )
def test ( root , k ) :
    nr = nextRightNodeUtil ( root , k )
    if ( nr != None ) :
        print ( " Next ▁ Right ▁ of " , k , " is " , nr . key )
    else :
        print ( " No ▁ next ▁ right ▁ node ▁ found ▁ for " , k )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 2 )
    root . right = newNode ( 6 )
    root . right . right = newNode ( 5 )
    root . left . left = newNode ( 8 )
    root . left . right = newNode ( 4 )
    test ( root , 10 )
    test ( root , 2 )
    test ( root , 6 )
    test ( root , 5 )
    test ( root , 8 )
    test ( root , 4 )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def threelargest ( root , first , second , third ) :
    if ( root == None ) :
        return
    if ( root . data > first [ 0 ] ) :
        third [ 0 ] = second [ 0 ]
        second [ 0 ] = first [ 0 ]
        first [ 0 ] = root . data
    elif ( root . data > second [ 0 ] and root . data != first [ 0 ] ) :
        third [ 0 ] = second [ 0 ]
        second [ 0 ] = root . data
    elif ( root . data > third [ 0 ] and root . data != first [ 0 ] and root . data != second [ 0 ] ) :
        third [ 0 ] = root . data
    threelargest ( root . left , first , second , third )
    threelargest ( root . right , first , second , third )
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 ( 4 )
    root . right . right = newNode ( 5 )
    first = [ 0 ]
    second = [ 0 ]
    third = [ 0 ]
    threelargest ( root , first , second , third )
    print ( " three ▁ largest ▁ elements ▁ are " , first [ 0 ] , second [ 0 ] , third [ 0 ] )

Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def findMax ( root ) :
    if ( root == None ) :
        return float ( ' - inf ' )
    res = root . data
    lres = findMax ( root . left )
    rres = findMax ( root . right )
    if ( lres > res ) :
        res = lres
    if ( rres > res ) :
        res = rres
    return res
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 2 )
    root . left = newNode ( 7 )
    root . right = newNode ( 5 )
    root . left . right = newNode ( 6 )
    root . left . right . left = newNode ( 1 )
    root . left . right . right = newNode ( 11 )
    root . right . right = newNode ( 9 )
    root . right . right . left = newNode ( 4 )
    print ( " Maximum ▁ element ▁ is " , findMax ( root ) )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def newNode ( val ) :
    temp = Node ( 0 )
    temp . data = val
    temp . left = None
    temp . right = None
    return temp
def inorderSuccessor ( root , target_node ) :
    global next
    if ( root == None ) :
        return
    inorderSuccessor ( root . right , target_node )
    if ( root . data == target_node . data ) :
        if ( next == None ) :
            print ( " inorder ▁ successor ▁ of " , root . data , " ▁ is : ▁ None " )
        else :
            print ( " inorder ▁ successor ▁ of " , root . data , " is : " , next . data )
    next = root
    inorderSuccessor ( root . left , target_node )
next = 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 . right = newNode ( 6 )
    next = None
    inorderSuccessor ( root , root . right )
    next = None
    inorderSuccessor ( root , root . left . left )
    next = None
    inorderSuccessor ( root , root . right . right )

Class/struct names: Node
Python program:
class graph ( object ) :
    def __init__ ( self , v ) :
        self . v = v
        self . graph = dict ( )
    def addEdge ( self , source , destination ) :
        if source not in self . graph :
            self . graph = { destination }
        else :
            self . graph . add ( destination )
        if destination not in self . graph :
            self . graph [ destination ] = { source }
        else :
            self . graph [ destination ] . add ( source )
    def print ( self ) :
        for i , adjlist in sorted ( self . graph . items ( ) ) :
            print ( " Adjacency ▁ list ▁ of ▁ vertex ▁ " , i )
            for j in sorted ( adjlist , reverse = True ) :
                print ( j , end = " ▁ " )
            print ( ' ' )
    def searchEdge ( self , source , destination ) :
        if source in self . graph :
            if destination in self . graph :
                print ( " Edge from { 0 } to { 1 } found . " . format ( source , destination ) )
            else :
                print ( " Edge from { 0 } to { 1 } not found . " . format ( source , destination ) )
        else :
            print ( " Source vertex { } is not present in graph . " . format ( source ) )
if __name__ == " _ _ main _ _ " :
    g = graph ( 5 )
    g . addEdge ( 0 , 1 )
    g . addEdge ( 0 , 4 )
    g . addEdge ( 1 , 2 )
    g . addEdge ( 1 , 3 )
    g . addEdge ( 1 , 4 )
    g . addEdge ( 2 , 3 )
    g . addEdge ( 3 , 4 )
    g . print ( )
    g . searchEdge ( 2 , 1 )
    g . searchEdge ( 0 , 3 )

Index/key variables: destination
Iterator variables: adjlist, i, j
Class/struct names: graph