#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Finding subset of integers

Posts: 2Member
Hi !

Can anyone write a code for the following:

Searching a set of Integers

You are given two sets of integers. S1 and S2. The size of S1 is less than sizeof S2, i.e. the number of integers in S1 is less than the number of integers in S2.
Neither S1, not S2 can be an empty set.

You have to find out whether the sequence of integers of S1 is there in S2.

e.g. S1 = { 1, 5, 6 }, and S2 = { 4, 7, 9, 1, 5, 6 }.

Here, you have found the S1 in S2 subset.

S1 = { 1, 9 }, and S2 = {5, 8, 9 , 1 }

S1 = { 2, 5 }, and S2 = {6, 2, 5, 7, 2, 5, 1 }
Here, S1 is found in S2, twice. You need to return all the instances.

You can do this in C/C++

· ·

• Posts: 3,711Member
: Hi !
:
: Can anyone write a code for the following:
:
: Searching a set of Integers

[blue]Yep, shouldn't be much of a problem.[/blue]

: You can do this in C/C++

[blue]Thanks.[/blue]

· ·
• Posts: 621Member
: Hi !
:
: Can anyone write a code for the following:
:
:
: Searching a set of Integers
:
: You are given two sets of integers. S1 and S2. The size of S1 is less than sizeof S2, i.e. the number of integers in S1 is less than the number of integers in S2.
: Neither S1, not S2 can be an empty set.
:
: You have to find out whether the sequence of integers of S1 is there in S2.
:
: e.g. S1 = { 1, 5, 6 }, and S2 = { 4, 7, 9, 1, 5, 6 }.
:
: Here, you have found the S1 in S2 subset.
:
: S1 = { 1, 9 }, and S2 = {5, 8, 9 , 1 }
:
: S1 = { 2, 5 }, and S2 = {6, 2, 5, 7, 2, 5, 1 }
: Here, S1 is found in S2, twice. You need to return all the instances.
:
: You can do this in C/C++
:
:

I think I can do it too!

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl/english/E_index.htm

· ·
• Posts: 765Member ✭✭✭
: S1 = { 1, 9 }, and S2 = {5, 8, 9 , 1 }
:

[blue]Huh? Looks to me like S1 is a subset of S2.

An easy C++ solution is to use the templated [italic]includes[/italic] function (defined in the [italic][/italic] header). NOTE: The two sets must be sorted first to use that function.[/blue]
· ·
• Posts: 2Member
So can post that code over here?

Thanks !

: : Hi !
: :
: : Can anyone write a code for the following:
: :
: :
: : Searching a set of Integers
: :
: : You are given two sets of integers. S1 and S2. The size of S1 is less than sizeof S2, i.e. the number of integers in S1 is less than the number of integers in S2.
: : Neither S1, not S2 can be an empty set.
: :
: : You have to find out whether the sequence of integers of S1 is there in S2.
: :
: : e.g. S1 = { 1, 5, 6 }, and S2 = { 4, 7, 9, 1, 5, 6 }.
: :
: : Here, you have found the S1 in S2 subset.
: :
: : S1 = { 1, 9 }, and S2 = {5, 8, 9 , 1 }
: :
: : S1 = { 2, 5 }, and S2 = {6, 2, 5, 7, 2, 5, 1 }
: : Here, S1 is found in S2, twice. You need to return all the instances.
: :
: : You can do this in C/C++
: :
: :
:
: I think I can do it too!
:
:
: Greets,
: Eric Goldstein
: http://www.gvh-maatwerk.nl/english/E_index.htm
:
:
:

· ·
• Posts: 621Member
: So can post that code over here?
:
: Thanks !
:

Can't you see we're just having fun over you?

This is obviously some kind of homework or school assignment.
Easy enough to do it yourself.

If you try and get stuck, we are more than willing to take a look at your code. But if you didn't even start to code anything yet, nobody will be willing to help you.

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl/english/E_index.htm

· ·