AND Operation on a two dimensional array



 DEVELOP > c-Plus-Plus > AND Operation on a two dimensional array

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Mugunth"
Date: 10 Jan 2008 08:26:10 PM
Object: 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?
.

User: "Tomás Ó hÉilidhe"

Title: Re: AND Operation on a two dimensional array 11 Jan 2008 11:24:21 AM
Mugunth <mugunth.kumar@gmail.com> wrote 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
.

User: "Victor Bazarov"

Title: Re: AND Operation on a two dimensional array 10 Jan 2008 09:16:57 PM
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
.

User: "Jim Langston"

Title: Re: AND Operation on a two dimensional array 14 Jan 2008 08:13:06 PM
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
tazmaster@rocketmail.com
.
User: "James Kanze"

Title: Re: AND Operation on a two dimensional array 15 Jan 2008 04:42:53 AM
On Jan 15, 3:13 am, "Jim Langston" <tazmas...@rocketmail.com> wrote:

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 =3D begin ;
if ( current !=3D end ) {
result =3D *current ;
std::sort( result.begin(), result.end() ) ;
++ current ;
}
while ( current !=3D 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:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
User: "Jim Langston"

Title: Re: AND Operation on a two dimensional array 15 Jan 2008 06:38:52 PM
James Kanze wrote:

On Jan 15, 3:13 am, "Jim Langston" <tazmas...@rocketmail.com> wrote:

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
tazmaster@rocketmail.com
.



User: "Ivan Novick"

Title: Re: AND Operation on a two dimensional array 10 Jan 2008 10:26:08 PM
On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.com> 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.

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
.
User: "Diego Martins"

Title: Re: AND Operation on a two dimensional array 11 Jan 2008 10:48:52 AM
On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.net> wrote:

On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.com> 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.


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
.
User: "Howard"

Title: Re: AND Operation on a two dimensional array 11 Jan 2008 08:06:27 PM
"Diego Martins" <jose.diego@gmail.com> wrote in message
news:204774a2-c46c-4eca-9437-648cc7ebfe20@j78g2000hsd.googlegroups.com...

On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.net> wrote:

On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.com> 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.


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
.
User: "Diego Martins"

Title: Re: AND Operation on a two dimensional array 14 Jan 2008 07:50:36 AM
On Jan 12, 12:06 am, "Howard" <m...@here.com> wrote:

"Diego Martins" <jose.di...@gmail.com> wrote in message

news:204774a2-c46c-4eca-9437-648cc7ebfe20@j78g2000hsd.googlegroups.com...



On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.net> wrote:

On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.com> 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.


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

thinking again, it is O(w^2 * h)
Diego
.
User: "Howard"

Title: Re: AND Operation on a two dimensional array 15 Jan 2008 06:29:42 PM
"Diego Martins" <jose.diego@gmail.com> wrote in message
news:8906da9e-2e1d-4215-a756-685f4df08566@q39g2000hsf.googlegroups.com...

On Jan 12, 12:06 am, "Howard" <m...@here.com> wrote:

"Diego Martins" <jose.di...@gmail.com> wrote in message

news:204774a2-c46c-4eca-9437-648cc7ebfe20@j78g2000hsd.googlegroups.com...



On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.net> wrote:

On Jan 10, 6:26 pm, Mugunth <mugunth.ku...@gmail.com> 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.


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


thinking again, it is O(w^2 * h)


**What** is O(w^2 * h)? You haven't suggested any sort of algorithm which
might have this cost or complexity, nor, for that matter, any reason at all
for your simple statement. What point are you trying to make?
-Howard
.






  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER