473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

AND Operation on a two dimensional array

What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
..
..
..

The result should be another array that contains only 6.

Any ideas?
Jan 11 '08 #1
8 1577
Mugunth wrote:
What is the most effective way of implementing an AND operation on a
two-d array.
What does that mean to perform AND on an array?
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
.
.
.

The result should be another array that contains only 6.
Why?
Any ideas?
Nope.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 11 '08 #2
On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.comwrote:
What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
The result should be another array that contains only 6.
It seems like you are trying to find a list of numbers which are in
every row of the 2-D array. Is that so?

Regards,
Ivan Novick
Jan 11 '08 #3
On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.netwrote:
On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.comwrote:
What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
The result should be another array that contains only 6.

It seems like you are trying to find a list of numbers which are in
every row of the 2-D array. Is that so?

Regards,
Ivan Novick
O(n^n)

O__O
Jan 11 '08 #4
Mugunth <mu***********@gmail.comwrote in comp.lang.c++:
What is the most effective way of implementing an AND operation on a
two-d array.

With the bitwise AND operator.

I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2

Since you've given a poor explanation, I can only guess that that's
equivalent to:

T arr[3][5] = { {1,3,5,6,7},{2,4,5,6,1},{8,6,4,9,2} };

The result should be another array that contains only 6.

This one's easy:

T arr[1] = {6};

Any ideas?

A better explanation might beg better replies.

--
Tomás Ó hÉilidhe
Jan 11 '08 #5

"Diego Martins" <jo********@gmail.comwrote in message
news:20**********************************@j78g2000 hsd.googlegroups.com...
On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.netwrote:
>On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.comwrote:
What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
The result should be another array that contains only 6.

It seems like you are trying to find a list of numbers which are in
every row of the 2-D array. Is that so?

Regards,
Ivan Novick

O(n^n)
Did you mean O(n^2)? Also, I don't think I get your point.

What algorithm are you considering employing which has that cost? Under
certain conditions, you can answer this question by going through the matrix
just once (but I can never remember if that's O(n), where n is the size of
the array, or O(w*h) where w and h are the width and height).

-Howard

Jan 12 '08 #6
Mugunth wrote:
What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
.
The result should be another array that contains only 6.

Any ideas?
You're not explaining exactly what it is your are trying to accomplish, but
it seems like a non optimal soulution would be:
sort each row
store the first row in an array we'll call working
go through each row and remove from working any value that is not in the row
return whatever is left

You are actually looking for a subset. The subset of the elements that are
in each set (row).

Is this the case?

--
Jim Langston
ta*******@rocketmail.com
Jan 15 '08 #7
On Jan 15, 3:13 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
Mugunth wrote:
What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
.
The result should be another array that contains only 6.
Any ideas?
You're not explaining exactly what it is your are trying to
accomplish, but it seems like a non optimal soulution would
be:
sort each row
store the first row in an array we'll call working
go through each row and remove from working any value that is
not in the row return whatever is left
Not sure how you can speak about a solution if you (admittedly)
don't know what the problem is:-). If it's what you think, then
sort each row, then use std::set_intersection. Something like:

typedef std::vector< int >
Row ;
typedef std::vector< Row >
Table ;

Row
findCommonElements(
Table::const_iterator
begin,
Table::const_iterator
end )
{
Row result ;
Table::const_iterator
current = begin ;
if ( current != end ) {
result = *current ;
std::sort( result.begin(), result.end() ) ;
++ current ;
}
while ( current != end ) {
Row tmp1( result ) ;
Row tmp2( *current ) ;
std::sort( tmp2.begin(), tmp2.end() ) ;
result.clear() ;
std::set_intersection(
tmp1.begin(), tmp1.end(),
tmp2.begin(), tmp2.end(),
std::back_inserter( result ) ) ;
++ current ;
}
return result ;
}
You are actually looking for a subset. The subset of the
elements that are in each set (row).
Is this the case?
Your description sounds more like a set intersection, treating
each row as a set.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 15 '08 #8
James Kanze wrote:
On Jan 15, 3:13 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
>Mugunth wrote:
>>What is the most effective way of implementing an AND operation on a
two-d array.
I've an array like,
1 3 5 6 7
2 4 5 6 1
8 6 4 9 2
.
The result should be another array that contains only 6.
>>Any ideas?
>You're not explaining exactly what it is your are trying to
accomplish, but it seems like a non optimal soulution would
be:
sort each row
store the first row in an array we'll call working
go through each row and remove from working any value that is
not in the row return whatever is left

Not sure how you can speak about a solution if you (admittedly)
don't know what the problem is:-).
That's true. My solution was an algorithm of one of the possible things the
OP was trying to accomplish. The OP was not clear on exactly what he was
trying to do.
If it's what you think, then
sort each row, then use std::set_intersection. Something like:

typedef std::vector< int >
Row ;
typedef std::vector< Row >
Table ;

Row
findCommonElements(
Table::const_iterator
begin,
Table::const_iterator
end )
{
Row result ;
Table::const_iterator
current = begin ;
if ( current != end ) {
result = *current ;
std::sort( result.begin(), result.end() ) ;
++ current ;
}
while ( current != end ) {
Row tmp1( result ) ;
Row tmp2( *current ) ;
std::sort( tmp2.begin(), tmp2.end() ) ;
result.clear() ;
std::set_intersection(
tmp1.begin(), tmp1.end(),
tmp2.begin(), tmp2.end(),
std::back_inserter( result ) ) ;
++ current ;
}
return result ;
}
>You are actually looking for a subset. The subset of the
elements that are in each set (row).
>Is this the case?

Your description sounds more like a set intersection, treating
each row as a set.
That's one possible explanation of the OP's post and the one I ran with,
asking if this was in fact what he was trying to accomplish.

--
Jim Langston
ta*******@rocketmail.com
Jan 16 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of...
16
by: rguti | last post by:
Hi, How do I create a two dimensional array? I have created a one dimensional doing this: Dim laFields As ArrayList = New ArrayList How about to do a 2 dimensional?
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
8
by: Martin Jørgensen | last post by:
Hi, "C primer plus" p.382: Suppose we have this declaration: int (*pa); int ar1; int ar2; int **p2;
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.