6 sorting/8 union of two sorted array/main.cpp
//Given two sorted arrays print union od two sorted arrays
Given two sorted arrays print union od two sorted arrays
Given two sorted arrays print union od two sorted arrays
void naive(int a[], int n1, int b[], int n2){   
    int c[n1+n2];
    for(int i=0; i<n1; i++){    
        c[i] = a[i];
    }
    for(int i=0; i<n2; i++){    
        c[n1+i] = b[i];
    }
    sort(c,c+(n1+n2));  
    for(int i=0; i<n1+n2; i++){
        if(i==0 || c[i]!=c[i-1])
            cout << c[i] << " ";
    }
}
void naive ( int a [ ] , int n1 , int b [ ] , int n2 ) { int c [ n1 + n2 ] ; for ( int i = 0 ; i < n1 ; i ++ ) { c [ i ] = a [ i ] ; } for ( int i = 0 ; i < n2 ; i ++ ) { c [ n1 + i ] = b [ i ] ; } sort ( c , c + ( n1 + n2 ) ) ; for ( int i = 0 ; i < n1 + n2 ; i ++ ) { if ( i == 0 || c [ i ] != c [ i - 1 ] ) cout << c [ i ] << " " ; } }
Given two sorted arrays print union od two sorted arrays
Given two sorted arrays print union od two sorted arrays
//Time=O((n1+n2)*log(n1+n2)) space=O(n1+n2) //O(n1) //O(n2) //O(log(n1+n2))