By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

comparing arrays

P: n/a
If I have two arrays, what is a good paradigm for comparing what is in
them, to determine what elements they share, or don't share?

Specifically, each array could potentially contain the integers 1 to
9, but probably not all 9 integers.

MyArray1 = 1,2,3,5,6,7,8
MyArray2 = 1,4,6,7

I would need the answers to be arrays too:
MyArrayShared: 1,6,7
MyArrayNotShared: 9

TIA
Jan 18 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 18 Jan 2006 10:16:32 GMT, Donald Grove
<do*********@verizon.net> wrote:

You could go brute-force since these are such small arrays. Just
iterate over the one, and for each element iterate over the second.

If you needed maximum speed then your algorithm should use all
additional information that is available, for example:
* the arrays are sorted
* the length of an array can be calculated very quickly
* MyArray1 is longer than MyArray2.
There may be other operational characteristics that you can leverage.

-Tom.

If I have two arrays, what is a good paradigm for comparing what is in
them, to determine what elements they share, or don't share?

Specifically, each array could potentially contain the integers 1 to
9, but probably not all 9 integers.

MyArray1 = 1,2,3,5,6,7,8
MyArray2 = 1,4,6,7

I would need the answers to be arrays too:
MyArrayShared: 1,6,7
MyArrayNotShared: 9

TIA


Jan 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.