Find whether an array is subset of another array using hashing O(n) Method 1

Find whether an array is subset of another array

time complexity O(n)

#include<stdio.h>
#include <iostream>
#include <set>
#include<iterator>


using namespace std;

int main ()
{

  std::set<int>myset;
  std::set<int>::iterator it;
  int arr[9]={1,2,3,4,5,6,7};
  int arr2[3]={1,2,5};
  int i, temp=true;

  for(i=0;i<6;i++)
  {
            myset.insert(arr[i]);

  }
  for(i=0;i<3;i++)
  {
      if(myset.count(arr2[i])!=1)
      {
        printf("not the subarray\n");
        temp=false;
        break;
      }

  }
  if(temp==true)
  {
      printf("This is the subarray\n");
  }

  return 0;
}

No comments:

Post a Comment

All Repeated Words In Text File And Their Occurrences In Java

Find All Repeated Words In Text File And Their Occurrences In Java Place your file location in the argument of the FileReader. If t...