dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < pair < int , int > > ans ; int flag = 1 ; int dfs ( vector < int > adj [ ] , int * order , int * bridge_detect , bool * mark , int v , int l ) { mark [ v ] = 1 ; order [ v ] = order [ l ] + 1 ; bridge_detect [ v ] = order [ v ] ; for ( int i = 0 ; i < adj [ v ] . size ( ) ; i ++ ) { int u = adj [ v ] [ i ] ; if ( u == l ) { continue ; } if ( order [ v ] < order [ u ] ) { continue ; } if ( mark [ u ] ) { bridge_detect [ v ] = min ( order [ u ] , bridge_detect [ v ] ) ; } else { dfs ( adj , order , bridge_detect , mark , u , v ) ; } bridge_detect [ v ] = min ( bridge_detect [ u ] , bridge_detect [ v ] ) ; ans . push_back ( make_pair ( v , u ) ) ; } if ( bridge_detect [ v ] == order [ v ] && l != 0 ) { flag = 0 ; } return flag ; } void convert ( vector < int > adj [ ] , int n ) { int order [ n ] = { 0 } ; int bridge_detect [ n ] = { 0 } ; bool mark [ n ] ; memset ( mark , false , sizeof ( mark ) ) ; int flag = dfs ( adj , order , bridge_detect , mark , 1 , 0 ) ; if ( flag == 0 ) { cout << " - 1" ; } else { for ( auto & it : ans ) { cout << it . first << " - > " << it . second << ' ' ; } } } void createGraph ( int Edges [ ] [ 2 ] , vector < int > adj [ ] , int M ) { for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } } int main ( ) { int N = 5 , M = 6 ; int Edges [ M ] [ 2 ] = { { 0 , 1 } , { 0 , 2 } , { 1 , 2 } , { 1 , 4 } , { 2 , 3 } , { 3 , 4 } } ; vector < int > adj [ N ] ; createGraph ( Edges , adj , M ) ; convert ( adj , N ) ; return 0 ; }

Index/key variables: M, N, i, l, n, u, v
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool increasing ( int a [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] >= a [ i + 1 ] ) return false ; return true ; } bool decreasing ( int a [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a [ i ] < a [ i + 1 ] ) return false ; return true ; } int shortestUnsorted ( int a [ ] , int n ) { if ( increasing ( a , n ) == true || decreasing ( a , n ) == true ) return 0 ; else return 3 ; } int main ( ) { int ar [ ] = { 7 , 9 , 10 , 8 , 11 } ; int n = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; cout << shortestUnsorted ( ar , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new ( struct Node ) ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int max ( int a , int b ) { return ( a >= b ) ? a : b ; } int maxPathSumUtil ( struct Node * root , int & res ) { if ( root == NULL ) return 0 ; if ( ! root -> left && ! root -> right ) return root -> data ; int ls = maxPathSumUtil ( root -> left , res ) ; int rs = maxPathSumUtil ( root -> right , res ) ; if ( root -> left && root -> right ) { res = max ( res , ls + rs + root -> data ) ; return max ( ls , rs ) + root -> data ; } return ( ! root -> left ) ? rs + root -> data : ls + root -> data ; } int maxPathSum ( struct Node * root ) { int res = INT_MIN ; int val = maxPathSumUtil ( root , res ) ; if ( res == INT_MIN ) { return val ; } return res ; } int main ( ) { struct Node * root = newNode ( -15 ) ; root -> left = newNode ( 5 ) ; root -> right = newNode ( 6 ) ; root -> left -> left = newNode ( -8 ) ; root -> left -> right = newNode ( 1 ) ; root -> left -> left -> left = newNode ( 2 ) ; root -> left -> left -> right = newNode ( 6 ) ; root -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 9 ) ; root -> right -> right -> right = newNode ( 0 ) ; root -> right -> right -> right -> left = newNode ( 4 ) ; root -> right -> right -> right -> right = newNode ( -1 ) ; root -> right -> right -> right -> right -> left = newNode ( 10 ) ; cout << " Max ▁ pathSum ▁ of ▁ the ▁ given ▁ binary ▁ tree ▁ is ▁ " << maxPathSum ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSwaps ( int arr [ ] , int n ) { pair < int , int > arrPos [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arrPos [ i ] . first = arr [ i ] ; arrPos [ i ] . second = i ; } sort ( arrPos , arrPos + n ) ; vector < bool > vis ( n , false ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] . second == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = 1 ; j = arrPos [ j ] . second ; cycle_size ++ ; } if ( cycle_size > 0 ) { ans += ( cycle_size - 1 ) ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 5 , 4 , 3 , 2 } ; int n = ( sizeof ( arr ) / sizeof ( int ) ) ; cout << minSwaps ( arr , n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: ans, cycle_size, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swap ( vector < int > & arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } int indexOf ( vector < int > & arr , int ele ) { for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] == ele ) { return i ; } } return -1 ; } int minSwaps ( vector < int > arr , int N ) { int ans = 0 ; vector < int > temp ( arr . begin ( ) , arr . end ( ) ) ; sort ( temp . begin ( ) , temp . end ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != temp [ i ] ) { ans ++ ; swap ( arr , i , indexOf ( arr , temp [ i ] ) ) ; } } return ans ; } int main ( ) { vector < int > a = { 101 , 758 , 315 , 730 , 472 , 619 , 460 , 479 } ; int n = a . size ( ) ; cout << minSwaps ( a , n ) ; }

Index/key variables: i, j
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swap ( vector < int > & arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } int minSwaps ( vector < int > arr , int N ) { int ans = 0 ; vector < int > temp = arr ; map < int , int > h ; sort ( temp . begin ( ) , temp . end ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { h [ arr [ i ] ] = i ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != temp [ i ] ) { ans ++ ; int init = arr [ i ] ; swap ( arr , i , h [ temp [ i ] ] ) ; h [ init ] = h [ temp [ i ] ] ; h [ temp [ i ] ] = i ; } } return ans ; } int main ( ) { vector < int > a = { 101 , 758 , 315 , 730 , 472 , 619 , 460 , 479 } ; int n = a . size ( ) ; cout << minSwaps ( a , n ) ; }

Index/key variables: i, init, j
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printUnion ( int arr1 [ ] , int arr2 [ ] , int m , int n ) { int i = 0 , j = 0 ; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) cout << arr1 [ i ++ ] << " ▁ " ; else if ( arr2 [ j ] < arr1 [ i ] ) cout << arr2 [ j ++ ] << " ▁ " ; else { cout << arr2 [ j ++ ] << " ▁ " ; i ++ ; } } while ( i < m ) cout << arr1 [ i ++ ] << " ▁ " ; while ( j < n ) cout << arr2 [ j ++ ] << " ▁ " ; } int main ( ) { int arr1 [ ] = { 1 , 2 , 4 , 5 , 6 } ; int arr2 [ ] = { 2 , 3 , 5 , 7 } ; int m = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; printUnion ( arr1 , arr2 , m , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; unordered_set < int > kPowKform ; int dp [ 100005 ] ; int func ( int n ) { if ( n <= 0 ) return 0 ; if ( kPowKform . count ( n ) ) return 1 ; if ( dp [ n ] != -1 ) return dp [ n ] ; int answer = 0 ; int x = n ; while ( x > 0 ) { int d = x % 10 ; if ( d != 0 ) { if ( func ( n - d * d ) ) { answer = 1 ; break ; } } x /= 10 ; } return dp [ n ] = answer ; } void canBeConverted ( int n ) { memset ( dp , -1 , sizeof ( dp ) ) ; if ( func ( n ) ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int N = 13 ; for ( int i = 1 ; i <= 8 ; i ++ ) { int val = 1 ; for ( int j = 1 ; j <= i ; j ++ ) val *= i ; kPowKform . insert ( val ) ; } canBeConverted ( N ) ; return 0 ; }

Index/key variables: n
Accumulator variables: i, j, stdc, val, x
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; class element { public : int A ; int B ; } ; void NumberOfWays ( int n , int k , int p , int q ) { element * dp = new element [ n ] ; if ( p == q ) { dp [ 0 ] . A = 1 ; dp [ 0 ] . B = 0 ; } else { dp [ 0 ] . A = 0 ; dp [ 0 ] . B = 1 ; } for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] . A = dp [ i - 1 ] . B ; dp [ i ] . B = ( dp [ i - 1 ] . A * ( k - 1 ) ) + ( dp [ i - 1 ] . B * ( k - 2 ) ) ; } cout << dp [ n - 1 ] . A << endl ; return ; } int main ( ) { int N = 5 ; int K = 3 ; int P = 2 ; int Q = 1 ; NumberOfWays ( N , K , P , Q ) ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: element
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) { int i = 0 , j = 0 ; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) i ++ ; else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ; else { cout << arr2 [ j ] << " ▁ " ; i ++ ; j ++ ; } } } int main ( ) { int arr1 [ ] = { 1 , 2 , 4 , 5 , 6 } ; int arr2 [ ] = { 2 , 3 , 5 , 7 } ; int m = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; printIntersection ( arr1 , arr2 , m , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPowerOfTwo ( int N ) { double number = log ( N ) / log ( 2 ) ; int checker = int ( number ) ; return number - checker == 0 ; } bool isSeriesFour ( int N , int digits ) { int upperBound = int ( pow ( 2 , digits ) + pow ( 2 , digits - 1 ) - 1 ) ; int lowerBound = int ( pow ( 2 , digits ) - 1 ) ; return ( N >= lowerBound ) && ( N < upperBound ) ; } string getPureNumber ( int N ) { string numbers [ N + 1 ] ; numbers [ 0 ] = " " ; int blocks = 0 ; int displacement = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { if ( isPowerOfTwo ( i + 1 ) ) { blocks = blocks + 1 ; } if ( isSeriesFour ( i , blocks ) ) { displacement = int ( pow ( 2 , blocks - 1 ) ) ; numbers [ i ] = "4" + numbers [ i - displacement ] + "4" ; } else { displacement = int ( pow ( 2 , blocks ) ) ; numbers [ i ] = "5" + numbers [ i - displacement ] + "5" ; } } return numbers [ N ] ; } int main ( ) { int N = 5 ; string pure = getPureNumber ( N ) ; cout << pure << endl ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 15 ] [ 2 ] ; string convertToString ( int num ) { stringstream ss ; ss << num ; string s = ss . str ( ) ; return s ; } int calculate ( int pos , int tight , int D [ ] , int sz , string & num ) { if ( pos == num . length ( ) ) return 1 ; if ( dp [ pos ] [ tight ] != -1 ) return dp [ pos ] [ tight ] ; int val = 0 ; if ( tight == 0 ) { for ( int i = 0 ; i < sz ; i ++ ) { if ( D [ i ] < ( num [ pos ] - '0' ) ) { val += calculate ( pos + 1 , 1 , D , sz , num ) ; } else if ( D [ i ] == num [ pos ] - '0' ) val += calculate ( pos + 1 , tight , D , sz , num ) ; } } else { for ( int i = 0 ; i < sz ; i ++ ) { val += calculate ( pos + 1 , tight , D , sz , num ) ; } } return dp [ pos ] [ tight ] = val ; } int countNumbers ( int D [ ] , int N , int sz ) { string num = convertToString ( N ) ; int len = num . length ( ) ; memset ( dp , -1 , sizeof ( dp ) ) ; int ans = calculate ( 0 , 0 , D , sz , num ) ; for ( int i = 1 ; i < len ; i ++ ) ans += calculate ( i , 1 , D , sz , num ) ; return ans ; } int main ( ) { int sz = 3 ; int D [ sz ] = { 1 , 4 , 9 } ; int N = 10 ; cout << countNumbers ( D , N , sz ) ; return 0 ; }

Index/key variables: i, pos, sz, tight
Accumulator variables: ans, i, stdc, val
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printUnion ( int * a , int n , int * b , int m ) { map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp . insert ( { a [ i ] , i } ) ; for ( int i = 0 ; i < m ; i ++ ) mp . insert ( { b [ i ] , i } ) ; cout << " The ▁ union ▁ set ▁ of ▁ both ▁ arrays ▁ is ▁ : " << endl ; for ( auto itr = mp . begin ( ) ; itr != mp . end ( ) ; itr ++ ) cout << itr -> first << " ▁ " ; } int main ( ) { int a [ 7 ] = { 1 , 2 , 5 , 6 , 2 , 3 , 5 } ; int b [ 9 ] = { 2 , 4 , 5 , 6 , 8 , 9 , 4 , 6 , 5 } ; printUnion ( a , 7 , b , 9 ) ; }

Index/key variables: i
Accumulator variables: i, itr, stdc
Iterator variables: i, itr
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1001 ] [ 1001 ] ; int find_max ( int i , int sum , vector < int > & v , int k ) { if ( i == v . size ( ) ) return 0 ; if ( dp [ i ] [ sum ] != -1 ) return dp [ i ] [ sum ] ; int ans = 0 ; if ( ( sum + find_max ( i + 1 , sum , v , k ) ) % k == 0 ) ans = find_max ( i + 1 , sum , v , k ) ; if ( ( sum + v [ i ] + find_max ( i + 1 , ( sum + v [ i ] ) % k , v , k ) ) % k == 0 ) ans = max ( ans , v [ i ] + find_max ( i + 1 , ( sum + v [ i ] ) % k , v , k ) ) ; return dp [ i ] [ sum ] = ans ; } int main ( ) { vector < int > arr = { 43 , 1 , 17 , 26 , 15 } ; int k = 16 ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << find_max ( 0 , 0 , arr , k ) ; }

Index/key variables: i, sum
Accumulator variables: stdc
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; int binarySearch ( int arr [ ] , int l , int r , int x ) ; void printUnion ( int arr1 [ ] , int arr2 [ ] , int m , int n ) { if ( m > n ) { int * tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; int temp = m ; m = n ; n = temp ; } sort ( arr1 , arr1 + m ) ; for ( int i = 0 ; i < m ; i ++ ) cout << arr1 [ i ] << " ▁ " ; for ( int i = 0 ; i < n ; i ++ ) if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) == -1 ) cout << arr2 [ i ] << " ▁ " ; } void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) { if ( m > n ) { int * tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; int temp = m ; m = n ; n = temp ; } sort ( arr1 , arr1 + m ) ; for ( int i = 0 ; i < n ; i ++ ) if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) != -1 ) cout << arr2 [ i ] << " ▁ " ; } 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 ; } int main ( ) { int arr1 [ ] = { 7 , 1 , 5 , 2 , 3 , 6 } ; int arr2 [ ] = { 3 , 8 , 6 , 20 , 7 } ; int m = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << " Union ▁ of ▁ two ▁ arrays ▁ is ▁ n " ; printUnion ( arr1 , arr2 , m , n ) ; cout << " nIntersection ▁ of ▁ two ▁ arrays ▁ is ▁ n " ; printIntersection ( arr1 , arr2 , m , n ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; bool printPath ( node * root , node * target_leaf ) { if ( root == NULL ) return false ; if ( root == target_leaf || printPath ( root -> left , target_leaf ) || printPath ( root -> right , target_leaf ) ) { cout << root -> data << " ▁ " ; return true ; } return false ; } void getTargetLeaf ( node * Node , int * max_sum_ref , int curr_sum , node * * target_leaf_ref ) { if ( Node == NULL ) return ; curr_sum = curr_sum + Node -> data ; if ( Node -> left == NULL && Node -> right == NULL ) { if ( curr_sum > * max_sum_ref ) { * max_sum_ref = curr_sum ; * target_leaf_ref = Node ; } } getTargetLeaf ( Node -> left , max_sum_ref , curr_sum , target_leaf_ref ) ; getTargetLeaf ( Node -> right , max_sum_ref , curr_sum , target_leaf_ref ) ; } int maxSumPath ( node * Node ) { if ( Node == NULL ) return 0 ; node * target_leaf ; int max_sum = INT_MIN ; getTargetLeaf ( Node , & max_sum , 0 , & target_leaf ) ; printPath ( Node , target_leaf ) ; return max_sum ; } node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } int main ( ) { node * root = NULL ; root = newNode ( 10 ) ; root -> left = newNode ( -2 ) ; root -> right = newNode ( 7 ) ; root -> left -> left = newNode ( 8 ) ; root -> left -> right = newNode ( -4 ) ; cout << " Following ▁ are ▁ the ▁ nodes ▁ on ▁ the ▁ maximum ▁ " " sum ▁ path ▁ STRNEWLINE " ; int sum = maxSumPath ( root ) ; cout << " Sum of the nodes is " return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void intersection ( int a [ ] , int b [ ] , int n , int m ) { int i = 0 , j = 0 ; while ( i < n && j < m ) { if ( a [ i ] > b [ j ] ) { j ++ ; } else if ( b [ j ] > a [ i ] ) { i ++ ; } else { cout << a [ i ] << " ▁ " ; i ++ ; j ++ ; } } } int main ( ) { int a [ ] = { 1 , 3 , 2 , 3 , 3 , 4 , 5 , 5 , 6 } ; int b [ ] = { 3 , 3 , 5 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int m = sizeof ( b ) / sizeof ( b [ 0 ] ) ; sort ( a , a + n ) ; sort ( b , b + m ) ; intersection ( a , b , n , m ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * newNode = new Node ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return ( newNode ) ; } int countUntil ( Node * root , int & res ) { if ( root == NULL ) return 0 ; int l = countUntil ( root -> left , res ) ; int r = countUntil ( root -> right , res ) ; int maxCount ; if ( root -> data == 1 ) maxCount = l + r + 1 ; else maxCount = l + r ; res = max ( res , maxCount ) ; if ( root -> data == 1 ) return max ( l , r ) + 1 ; else return max ( l , r ) ; } int findMaxCount ( Node * root ) { int res = INT_MIN ; countUntil ( root , res ) ; return res ; } int main ( void ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 0 ) ; root -> right = newNode ( 1 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 1 ) ; root -> left -> right -> left = newNode ( 1 ) ; root -> left -> right -> right = newNode ( 0 ) ; cout << findMaxCount ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printUnion ( int arr1 [ ] , int arr2 [ ] , int n1 , int n2 ) { set < int > hs ; for ( int i = 0 ; i < n1 ; i ++ ) hs . insert ( arr1 [ i ] ) ; for ( int i = 0 ; i < n2 ; i ++ ) hs . insert ( arr2 [ i ] ) ; for ( auto it = hs . begin ( ) ; it != hs . end ( ) ; it ++ ) cout << * it << " ▁ " ; cout << endl ; } void printIntersection ( int arr1 [ ] , int arr2 [ ] , int n1 , int n2 ) { set < int > hs ; for ( int i = 0 ; i < n1 ; i ++ ) hs . insert ( arr1 [ i ] ) ; for ( int i = 0 ; i < n2 ; i ++ ) if ( hs . find ( arr2 [ i ] ) != hs . end ( ) ) cout << arr2 [ i ] << " ▁ " ; } int main ( ) { int arr1 [ ] = { 7 , 1 , 5 , 2 , 3 , 6 } ; int arr2 [ ] = { 3 , 8 , 6 , 20 , 7 } ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int n2 = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; printUnion ( arr1 , arr2 , n1 , n2 ) ; printIntersection ( arr1 , arr2 , n1 , n2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int index ( vector < int > vec , int value ) { vector < int > :: iterator it ; it = find ( vec . begin ( ) , vec . end ( ) , value ) ; return ( it - vec . begin ( ) ) ; } int findCount ( int N ) { vector < int > list ; int sum = 0 ; int i ; for ( i = 0 ; i < 20 ; i ++ ) { sum += pow ( 2 , i ) ; list . push_back ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( list [ i ] >= N ) { return ( index ( list , list [ i ] ) + 1 ) ; } } } int main ( ) { int N = 10 ; cout << findCount ( N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sort012 ( int a [ ] , int arr_size ) { int lo = 0 ; int hi = arr_size - 1 ; int mid = 0 ; while ( mid <= hi ) { switch ( a [ mid ] ) { case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ; break ; case 1 : mid ++ ; break ; case 2 : swap ( a [ mid ] , a [ hi -- ] ) ; break ; } } } void printArray ( int arr [ ] , int arr_size ) { for ( int i = 0 ; i < arr_size ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort012 ( arr , n ) ; cout << " array ▁ after ▁ segregation ▁ " ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: hi, i, lo, mid, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSetBits ( int n ) { int dp [ n + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; cout << dp [ 0 ] << " ▁ " ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { dp [ i ] = dp [ i / 2 ] ; } else { dp [ i ] = dp [ i / 2 ] + 1 ; } cout << dp [ i ] << " ▁ " ; } } int main ( ) { int n = 5 ; findSetBits ( n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void sortArr ( int arr [ ] , int n ) { int i , cnt0 = 0 , cnt1 = 0 , cnt2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { switch ( arr [ i ] ) { case 0 : cnt0 ++ ; break ; case 1 : cnt1 ++ ; break ; case 2 : cnt2 ++ ; break ; } } i = 0 ; while ( cnt0 > 0 ) { arr [ i ++ ] = 0 ; cnt0 -- ; } while ( cnt1 > 0 ) { arr [ i ++ ] = 1 ; cnt1 -- ; } while ( cnt2 > 0 ) { arr [ i ++ ] = 2 ; cnt2 -- ; } printArr ( arr , n ) ; } int main ( ) { int arr [ ] = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; sortArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt0, cnt1, cnt2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int subsetSum ( int a [ ] , int n , int sum ) { int tab [ n + 1 ] [ sum + 1 ] ; tab [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= sum ; i ++ ) tab [ 0 ] [ i ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) tab [ i ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( a [ i - 1 ] > j ) tab [ i ] [ j ] = tab [ i - 1 ] [ j ] ; else { tab [ i ] [ j ] = tab [ i - 1 ] [ j ] + tab [ i - 1 ] [ j - a [ i - 1 ] ] ; } } } return tab [ n ] [ sum ] ; } int main ( ) { int n = 4 ; int a [ ] = { 3 , 3 , 3 , 3 } ; int sum = 6 ; cout << ( subsetSum ( a , n , sum ) ) ; }

Index/key variables: i, j, n, sum
Accumulator variables: i, j, stdc
Iterator variables: i, j