dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; public class JumpSearch { public static int jumpSearch ( int [ ] arr , int x ) { int n = arr . Length ; int step = ( int ) Math . Floor ( Math . Sqrt ( n ) ) ; int prev = 0 ; while ( arr [ Math . Min ( step , n ) - 1 ] < x ) { prev = step ; step += ( int ) Math . Floor ( Math . Sqrt ( n ) ) ; if ( prev >= n ) return - 1 ; } while ( arr [ prev ] < x ) { prev ++ ; if ( prev == Math . Min ( step , n ) ) return - 1 ; } if ( arr [ prev ] == x ) return prev ; return - 1 ; } public static void Main ( ) { int [ ] arr = { 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 610 } ; int x = 55 ; int index = jumpSearch ( arr , x ) ; Console . Write ( " Number ▁ " + x + " ▁ is ▁ at ▁ index ▁ " + index ) ; } }

Index/key variables: prev
Accumulator variables: prev, step
Class/struct names: JumpSearch
C# program:
using System ; class GFG { static int interpolationSearch ( int [ ] arr , int lo , int hi , int x ) { int pos ; if ( lo <= hi && x >= arr [ lo ] && 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 ; } public static void Main ( ) { int [ ] arr = new int [ ] { 10 , 12 , 13 , 16 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 33 , 35 , 42 , 47 } ; int n = arr . Length ; int x = 18 ; int index = interpolationSearch ( arr , 0 , n - 1 , x ) ; if ( index != - 1 ) Console . WriteLine ( " Element ▁ found ▁ at ▁ index ▁ " + index ) ; else Console . WriteLine ( " Element ▁ not ▁ found . " ) ; } }

Index/key variables: hi, lo, pos
Class/struct names: GFG
C# program:
using System ; class GFG { static int exponentialSearch ( int [ ] arr , int n , int x ) { if ( arr [ 0 ] == x ) return 0 ; int i = 1 ; while ( i < n && arr [ i ] <= x ) i = i * 2 ; return binarySearch ( arr , i / 2 , Math . Min ( i , n - 1 ) , x ) ; } static int binarySearch ( int [ ] arr , int l , int r , int x ) { if ( r >= l ) { int mid = l + ( r - l ) / 2 ; if ( arr [ mid ] == x ) return mid ; if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ; return binarySearch ( arr , mid + 1 , r , x ) ; } return - 1 ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 10 , 40 } ; int n = arr . Length ; int x = 10 ; int result = exponentialSearch ( arr , n , x ) ; if ( result == - 1 ) Console . Write ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) ; else Console . Write ( " Element ▁ is ▁ present ▁ at ▁ index ▁ " + result ) ; } }

Index/key variables: i, mid
Class/struct names: GFG
C# program:
using System ; class MergeSort { void merge ( int [ ] arr , int l , int m , int r ) { int n1 = m - l + 1 ; int n2 = r - m ; int [ ] L = new int [ n1 ] ; int [ ] R = new int [ n2 ] ; int i , j ; for ( i = 0 ; i < n1 ; ++ i ) L [ i ] = arr [ l + i ] ; for ( j = 0 ; j < n2 ; ++ j ) R [ j ] = arr [ m + 1 + j ] ; i = 0 ; j = 0 ; int k = l ; while ( i < n1 && j < n2 ) { if ( L [ i ] <= R [ j ] ) { arr [ k ] = L [ i ] ; i ++ ; } else { arr [ k ] = R [ j ] ; j ++ ; } k ++ ; } while ( i < n1 ) { arr [ k ] = L [ i ] ; i ++ ; k ++ ; } while ( j < n2 ) { arr [ k ] = R [ j ] ; j ++ ; k ++ ; } } void sort ( int [ ] arr , int l , int r ) { if ( l < r ) { int m = l + ( r - l ) / 2 ; sort ( arr , l , m ) ; sort ( arr , m + 1 , r ) ; merge ( arr , l , m , r ) ; } } static void printArray ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n ; ++ i ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 12 , 11 , 13 , 5 , 6 , 7 } ; Console . WriteLine ( " Given ▁ Array " ) ; printArray ( arr ) ; MergeSort ob = new MergeSort ( ) ; ob . sort ( arr , 0 , arr . Length - 1 ) ; Console . WriteLine ( " STRNEWLINE Sorted ▁ array " ) ; printArray ( arr ) ; } }

Index/key variables: i, j, k, n1, n2
Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: MergeSort
C# program:
using System ; class GFG { public static int getMax ( int [ ] arr , int n ) { int mx = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > mx ) mx = arr [ i ] ; return mx ; } public static void countSort ( int [ ] arr , int n , int exp ) { int [ ] output = new int [ n ] ; int i ; int [ ] count = new int [ 10 ] ; for ( i = 0 ; i < 10 ; i ++ ) count [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) count [ ( arr [ i ] / exp ) % 10 ] ++ ; for ( i = 1 ; i < 10 ; i ++ ) count [ i ] += count [ i - 1 ] ; for ( i = n - 1 ; i >= 0 ; i -- ) { output [ count [ ( arr [ i ] / exp ) % 10 ] - 1 ] = arr [ i ] ; count [ ( arr [ i ] / exp ) % 10 ] -- ; } for ( i = 0 ; i < n ; i ++ ) arr [ i ] = output [ i ] ; } public static void radixsort ( int [ ] arr , int n ) { int m = getMax ( arr , n ) ; for ( int exp = 1 ; m / exp > 0 ; exp *= 10 ) countSort ( arr , n , exp ) ; } public static void print ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } public static void Main ( ) { int [ ] arr = { 170 , 45 , 75 , 90 , 802 , 24 , 2 , 66 } ; int n = arr . Length ; radixsort ( arr , n ) ; print ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: exp, i
Iterator variables: exp, i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void bucketSort ( float [ ] arr , int n ) { if ( n <= 0 ) return ; List < float > [ ] buckets = new List < float > [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { buckets [ i ] = new List < float > ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { float idx = arr [ i ] * n ; buckets [ ( int ) idx ] . Add ( arr [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { buckets [ i ] . Sort ( ) ; } int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < buckets [ i ] . Count ; j ++ ) { arr [ index ++ ] = buckets [ i ] [ j ] ; } } } public static void Main ( ) { float [ ] arr = { ( float ) 0.897 , ( float ) 0.565 , ( float ) 0.656 , ( float ) 0.1234 , ( float ) 0.665 , ( float ) 0.3434 } ; int n = arr . Length ; bucketSort ( arr , n ) ; Console . WriteLine ( " Sorted ▁ array ▁ is ▁ " ) ; foreach ( float el in arr ) { Console . Write ( el + " ▁ " ) ; } } }

Index/key variables: i, j, n
Accumulator variables: i, index, j
Iterator variables: el, i, j
Class/struct names: GFG
C# program:
using System ; class ShellSort { static void printArray ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n ; ++ i ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } int sort ( int [ ] arr ) { int n = arr . Length ; for ( int gap = n / 2 ; gap > 0 ; gap /= 2 ) { for ( int i = gap ; i < n ; i += 1 ) { int temp = arr [ i ] ; int j ; for ( j = i ; j >= gap && arr [ j - gap ] > temp ; j -= gap ) arr [ j ] = arr [ j - gap ] ; arr [ j ] = temp ; } } return 0 ; } public static void Main ( ) { int [ ] arr = { 12 , 34 , 54 , 2 , 3 } ; Console . Write ( " Array ▁ before ▁ sorting ▁ : STRNEWLINE " ) ; printArray ( arr ) ; ShellSort ob = new ShellSort ( ) ; ob . sort ( arr ) ; Console . Write ( " Array ▁ after ▁ sorting ▁ : STRNEWLINE " ) ; printArray ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: gap, i, j
Iterator variables: gap, i, j
Class/struct names: ShellSort
C# program:
using System ; class GFG { static int getNextGap ( int gap ) { gap = ( gap * 10 ) / 13 ; if ( gap < 1 ) return 1 ; return gap ; } static void sort ( int [ ] arr ) { int n = arr . Length ; int gap = n ; bool swapped = true ; while ( gap != 1 swapped == true ) { gap = getNextGap ( gap ) ; swapped = false ; for ( int i = 0 ; i < n - gap ; i ++ ) { if ( arr [ i ] > arr [ i + gap ] ) { int temp = arr [ i ] ; arr [ i ] = arr [ i + gap ] ; arr [ i + gap ] = temp ; swapped = true ; } } } } public static void Main ( ) { int [ ] arr = { 8 , 4 , 1 , 56 , 3 , - 44 , 23 , - 6 , 28 , 0 } ; sort ( arr ) ; Console . WriteLine ( " sorted ▁ array " ) ; for ( int i = 0 ; i < arr . Length ; ++ i ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: swapped
Class/struct names: GFG
C# program:
using System ; class GFG { public static void cycleSort ( int [ ] arr , int n ) { int writes = 0 ; for ( int cycle_start = 0 ; cycle_start <= n - 2 ; cycle_start ++ ) { int item = arr [ cycle_start ] ; int pos = cycle_start ; for ( int i = cycle_start + 1 ; i < n ; i ++ ) if ( arr [ i ] < item ) pos ++ ; if ( pos == cycle_start ) continue ; while ( item == arr [ pos ] ) pos += 1 ; if ( pos != cycle_start ) { int temp = item ; item = arr [ pos ] ; arr [ pos ] = temp ; writes ++ ; } while ( pos != cycle_start ) { pos = cycle_start ; for ( int i = cycle_start + 1 ; i < n ; i ++ ) if ( arr [ i ] < item ) pos += 1 ; while ( item == arr [ pos ] ) pos += 1 ; if ( item != arr [ pos ] ) { int temp = item ; item = arr [ pos ] ; arr [ pos ] = temp ; writes ++ ; } } } } public static void Main ( ) { int [ ] arr = { 1 , 8 , 3 , 9 , 10 , 10 , 2 , 4 } ; int n = arr . Length ; cycleSort ( arr , n ) ; Console . Write ( " After ▁ sort ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: cycle_start, i, pos
Accumulator variables: cycle_start, i, pos, writes
Iterator variables: cycle_start, i
Class/struct names: GFG
C# program:
using System ; public class Node { public int data ; public Node next ; public Node ( int key ) { this . data = key ; next = null ; } } class GFG { static Node mergeSort ( Node head ) { if ( head . next == null ) return head ; Node mid = findMid ( head ) ; Node head2 = mid . next ; mid . next = null ; Node newHead1 = mergeSort ( head ) ; Node newHead2 = mergeSort ( head2 ) ; Node finalHead = merge ( newHead1 , newHead2 ) ; return finalHead ; } static Node merge ( Node head1 , Node head2 ) { Node merged = new Node ( - 1 ) ; Node temp = merged ; while ( head1 != null && head2 != null ) { if ( head1 . data < head2 . data ) { temp . next = head1 ; head1 = head1 . next ; } else { temp . next = head2 ; head2 = head2 . next ; } temp = temp . next ; } while ( head1 != null ) { temp . next = head1 ; head1 = head1 . next ; temp = temp . next ; } while ( head2 != null ) { temp . next = head2 ; head2 = head2 . next ; temp = temp . next ; } return merged . next ; } static Node findMid ( Node head ) { Node slow = head , fast = head . next ; while ( fast != null && fast . next != null ) { slow = slow . next ; fast = fast . next . next ; } return slow ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { Node head = new Node ( 7 ) ; Node temp = head ; temp . next = new Node ( 10 ) ; temp = temp . next ; temp . next = new Node ( 5 ) ; temp = temp . next ; temp . next = new Node ( 20 ) ; temp = temp . next ; temp . next = new Node ( 3 ) ; temp = temp . next ; temp . next = new Node ( 2 ) ; temp = temp . next ; head = mergeSort ( head ) ; Console . Write ( " STRNEWLINE Sorted ▁ Linked ▁ List ▁ is : ▁ STRNEWLINE " ) ; printList ( head ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { static int partition ( int [ ] arr , int low , int high ) { int temp ; int pivot = arr [ high ] ; int i = ( low - 1 ) ; for ( int j = low ; j <= high - 1 ; j ++ ) { if ( arr [ j ] <= pivot ) { i ++ ; temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } temp = arr [ i + 1 ] ; arr [ i + 1 ] = arr [ high ] ; arr [ high ] = temp ; return i + 1 ; } static void qSort ( int [ ] arr , int low , int high ) { if ( low < high ) { int pi = partition ( arr , low , high ) ; qSort ( arr , low , pi - 1 ) ; qSort ( arr , pi + 1 , high ) ; } } public static void Main ( ) { int n = 5 ; int [ ] arr = { 4 , 2 , 6 , 9 , 2 } ; qSort ( arr , 0 , n - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: high, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int partition ( int [ ] arr , int low , int high ) { int temp ; int pivot = arr [ high ] ; int i = ( low - 1 ) ; for ( int j = low ; j <= high - 1 ; j ++ ) { if ( arr [ j ] <= pivot ) { i ++ ; temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } temp = arr [ i + 1 ] ; arr [ i + 1 ] = arr [ high ] ; arr [ high ] = temp ; return i + 1 ; } static void quickSortIterative ( int [ ] arr , int l , int h ) { int [ ] stack = new int [ h - l + 1 ] ; int top = - 1 ; stack [ ++ top ] = l ; stack [ ++ top ] = h ; while ( top >= 0 ) { h = stack [ top -- ] ; l = stack [ top -- ] ; int p = partition ( arr , l , h ) ; if ( p - 1 > l ) { stack [ ++ top ] = l ; stack [ ++ top ] = p - 1 ; } if ( p + 1 < h ) { stack [ ++ top ] = p + 1 ; stack [ ++ top ] = h ; } } } public static void Main ( ) { int [ ] arr = { 4 , 3 , 5 , 2 , 1 , 3 , 2 , 3 } ; int n = 8 ; quickSortIterative ( arr , 0 , n - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: high, i, j
Accumulator variables: i, j, top
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void countSort ( int [ ] arr , int n , int exp ) { int [ ] output = new int [ n ] ; int [ ] count = new int [ n ] ; int i ; for ( i = 0 ; i < n ; i ++ ) count [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) count [ ( arr [ i ] / exp ) % n ] ++ ; for ( i = 1 ; i < n ; i ++ ) count [ i ] += count [ i - 1 ] ; for ( i = n - 1 ; i >= 0 ; i -- ) { output [ count [ ( arr [ i ] / exp ) % n ] - 1 ] = arr [ i ] ; count [ ( arr [ i ] / exp ) % n ] -- ; } for ( i = 0 ; i < n ; i ++ ) arr [ i ] = output [ i ] ; } static void sort ( int [ ] arr , int n ) { countSort ( arr , n , 1 ) ; countSort ( arr , n , n ) ; } static void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } static public void Main ( ) { int [ ] arr = { 40 , 12 , 45 , 32 , 33 , 1 , 22 } ; int n = arr . Length ; Console . WriteLine ( " Given ▁ array " ) ; printArr ( arr , n ) ; sort ( arr , n ) ; Console . WriteLine ( " STRNEWLINE Sorted ▁ array " ) ; printArr ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { int binarySearch ( int [ ] arr , int l , int r , int x ) { if ( r >= l ) { int mid = l + ( r - l ) / 2 ; if ( arr [ mid ] == x ) return mid ; if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ; if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ; if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ; return binarySearch ( arr , mid + 2 , r , x ) ; } return - 1 ; } public static void Main ( ) { GFG ob = new GFG ( ) ; int [ ] arr = { 3 , 2 , 10 , 4 , 40 } ; int n = arr . Length ; int x = 4 ; int result = ob . binarySearch ( arr , 0 , n - 1 , x ) ; if ( result == - 1 ) Console . Write ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) ; else Console . Write ( " Element ▁ is ▁ present ▁ at ▁ index ▁ " + result ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; class GFG { static void printClosest ( int [ ] ar1 , int [ ] ar2 , int m , int n , int x ) { int diff = int . MaxValue ; int res_l = 0 , res_r = 0 ; int l = 0 , r = n - 1 ; while ( l < m && r >= 0 ) { if ( Math . Abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) { res_l = l ; res_r = r ; diff = Math . Abs ( ar1 [ l ] + ar2 [ r ] - x ) ; } if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ; else l ++ ; } Console . Write ( " The ▁ closest ▁ pair ▁ is ▁ [ " + ar1 [ res_l ] + " , ▁ " + ar2 [ res_r ] + " ] " ) ; } public static void Main ( ) { int [ ] ar1 = { 1 , 4 , 5 , 7 } ; int [ ] ar2 = { 10 , 20 , 30 , 40 } ; int m = ar1 . Length ; int n = ar2 . Length ; int x = 38 ; printClosest ( ar1 , ar2 , m , n , x ) ; } }

Index/key variables: l, r, res_l, res_r
Accumulator variables: l, r
Class/struct names: GFG
C# program:
using System ; class GFG { static void printClosest ( int [ ] arr , int n , int x ) { int res_l = 0 , res_r = 0 ; int l = 0 , r = n - 1 , diff = int . MaxValue ; while ( r > l ) { if ( Math . Abs ( arr [ l ] + arr [ r ] - x ) < diff ) { res_l = l ; res_r = r ; diff = Math . Abs ( arr [ l ] + arr [ r ] - x ) ; } if ( arr [ l ] + arr [ r ] > x ) r -- ; else l ++ ; } Console . Write ( " ▁ The ▁ closest ▁ pair ▁ is ▁ " + arr [ res_l ] + " ▁ and ▁ " + arr [ res_r ] ) ; } public static void Main ( ) { int [ ] arr = { 10 , 22 , 28 , 29 , 30 , 40 } ; int x = 54 ; int n = arr . Length ; printClosest ( arr , n , x ) ; } }

Index/key variables: l, r, res_l, res_r
Accumulator variables: l, r
Class/struct names: GFG
C# program:
using System ; class GFG { static int countOnes ( int [ ] arr , int low , int high ) { if ( high >= low ) { int mid = low + ( high - low ) / 2 ; if ( ( mid == high arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ; if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ; return countOnes ( arr , low , ( mid - 1 ) ) ; } return 0 ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 1 , 1 , 0 , 0 , 0 } ; int n = arr . Length ; Console . WriteLine ( " Count ▁ of ▁ 1 ' s ▁ in ▁ given ▁ " + " array ▁ is ▁ " + countOnes ( arr , 0 , n - 1 ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; class GFG { public static void minimumSwaps ( int [ ] a , int n ) { int maxx = - 1 , l = 0 , minn = a [ 0 ] , r = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > maxx ) { maxx = a [ i ] ; l = i ; } if ( a [ i ] <= minn ) { minn = a [ i ] ; r = i ; } } if ( r < l ) Console . WriteLine ( l + ( n - r - 2 ) ) ; else Console . WriteLine ( l + ( n - r - 1 ) ) ; } public static void Main ( ) { int [ ] a = { 5 , 6 , 1 , 3 } ; int n = a . Length ; minimumSwaps ( a , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static void printMaxActivities ( int [ ] s , int [ ] f , int n ) { int i , j ; Console . Write ( " Following ▁ activities ▁ are ▁ selected ▁ : ▁ " ) ; i = 0 ; Console . Write ( i + " ▁ " ) ; for ( j = 1 ; j < n ; j ++ ) { if ( s [ j ] >= f [ i ] ) { Console . Write ( j + " ▁ " ) ; i = j ; } } } public static void Main ( ) { int [ ] s = { 1 , 3 , 0 , 5 , 8 , 5 } ; int [ ] f = { 2 , 4 , 6 , 7 , 9 , 9 } ; int n = s . Length ; printMaxActivities ( s , f , n ) ; } }

Index/key variables: i, j
Accumulator variables: j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class LIS { static int lis ( int [ ] arr , int n ) { int [ ] lis = new int [ n ] ; int i , j , max = 0 ; for ( i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ; return max ; } public static void Main ( ) { int [ ] arr = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 } ; int n = arr . Length ; Console . WriteLine ( " Length ▁ of ▁ lis ▁ is ▁ " + lis ( arr , n ) + " STRNEWLINE " ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: LIS
C# program:
using System ; class GFG { static int lcs ( char [ ] X , char [ ] Y , int m , int n ) { if ( m == 0 n == 0 ) return 0 ; if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ; else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ; } static int max ( int a , int b ) { return ( a > b ) ? a : b ; } public static void Main ( ) { String s1 = " AGGTAB " ; String s2 = " GXTXAYB " ; char [ ] X = s1 . ToCharArray ( ) ; char [ ] Y = s2 . ToCharArray ( ) ; int m = X . Length ; int n = Y . Length ; Console . Write ( " Length ▁ of ▁ LCS ▁ is " + " ▁ " + lcs ( X , Y , m , n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int lcs ( char [ ] X , char [ ] Y , int m , int n ) { int [ , ] L = new int [ m + 1 , n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i , j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) L [ i , j ] = L [ i - 1 , j - 1 ] + 1 ; else L [ i , j ] = max ( L [ i - 1 , j ] , L [ i , j - 1 ] ) ; } } return L [ m , n ] ; } static int max ( int a , int b ) { return ( a > b ) ? a : b ; } public static void Main ( ) { String s1 = " AGGTAB " ; String s2 = " GXTXAYB " ; char [ ] X = s1 . ToCharArray ( ) ; char [ ] Y = s2 . ToCharArray ( ) ; int m = X . Length ; int n = Y . Length ; Console . Write ( " Length ▁ of ▁ LCS ▁ is " + " ▁ " + lcs ( X , Y , m , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minDis ( string s1 , string s2 , int n , int m , List < List < int > > dp ) { if ( n == 0 ) return m ; if ( m == 0 ) return n ; if ( dp [ n ] [ m ] != - 1 ) return dp [ n ] [ m ] ; if ( s1 [ n - 1 ] == s2 [ m - 1 ] ) { if ( dp [ n - 1 ] [ m - 1 ] == - 1 ) { return dp [ n ] [ m ] = minDis ( s1 , s2 , n - 1 , m - 1 , dp ) ; } else return dp [ n ] [ m ] = dp [ n - 1 ] [ m - 1 ] ; } else { int m1 , m2 , m3 ; if ( dp [ n - 1 ] [ m ] != - 1 ) { m1 = dp [ n - 1 ] [ m ] ; } else { m1 = minDis ( s1 , s2 , n - 1 , m , dp ) ; } if ( dp [ n ] [ m - 1 ] != - 1 ) { m2 = dp [ n ] [ m - 1 ] ; } else { m2 = minDis ( s1 , s2 , n , m - 1 , dp ) ; } if ( dp [ n - 1 ] [ m - 1 ] != - 1 ) { m3 = dp [ n - 1 ] [ m - 1 ] ; } else { m3 = minDis ( s1 , s2 , n - 1 , m - 1 , dp ) ; } return dp [ n ] [ m ] = 1 + Math . Min ( m1 , Math . Min ( m2 , m3 ) ) ; } } static void Main ( ) { string str1 = " voldemort " ; string str2 = " dumbledore " ; int n = str1 . Length , m = str2 . Length ; List < List < int > > dp = new List < List < int > > ( ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { dp . Add ( new List < int > ( ) ) ; for ( int j = 0 ; j < m + 1 ; j ++ ) { dp [ i ] . Add ( - 1 ) ; } } Console . WriteLine ( minDis ( str1 , str2 , n , m , dp ) ) ; } }

Index/key variables: i, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int min ( int x , int y , int z ) { if ( x < y ) return ( ( x < z ) ? x : z ) ; else return ( ( y < z ) ? y : z ) ; } static int minCost ( int [ , ] cost , int m , int n ) { if ( n < 0 m < 0 ) return int . MaxValue ; else if ( m == 0 && n == 0 ) return cost [ m , n ] ; else return cost [ m , n ] + min ( minCost ( cost , m - 1 , n - 1 ) , minCost ( cost , m - 1 , n ) , minCost ( cost , m , n - 1 ) ) ; } public static void Main ( ) { int [ , ] cost = { { 1 , 2 , 3 } , { 4 , 8 , 2 } , { 1 , 5 , 3 } } ; Console . Write ( minCost ( cost , 2 , 2 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { private static int minCost ( int [ , ] cost , int m , int n ) { int i , j ; int [ , ] tc = new int [ m + 1 , n + 1 ] ; tc [ 0 , 0 ] = cost [ 0 , 0 ] ; for ( i = 1 ; i <= m ; i ++ ) tc [ i , 0 ] = tc [ i - 1 , 0 ] + cost [ i , 0 ] ; for ( j = 1 ; j <= n ; j ++ ) tc [ 0 , j ] = tc [ 0 , j - 1 ] + cost [ 0 , j ] ; for ( i = 1 ; i <= m ; i ++ ) for ( j = 1 ; j <= n ; j ++ ) tc [ i , j ] = min ( tc [ i - 1 , j - 1 ] , tc [ i - 1 , j ] , tc [ i , j - 1 ] ) + cost [ i , j ] ; return tc [ m , n ] ; } private static int min ( int x , int y , int z ) { if ( x < y ) return ( x < z ) ? x : z ; else return ( y < z ) ? y : z ; } public static void Main ( ) { int [ , ] cost = { { 1 , 2 , 3 } , { 4 , 8 , 2 } , { 1 , 5 , 3 } } ; Console . Write ( minCost ( cost , 2 , 2 ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG