473,791 Members | 3,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1597
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.ne twrote:
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********@gma il.comwrote in message
news:20******** *************** ***********@j78 g2000hsd.google groups.com...
On Jan 11, 2:26 am, Ivan Novick <i...@0x4849.ne twrote:
>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*******@rocke tmail.com
Jan 15 '08 #7
On Jan 15, 3:13 am, "Jim Langston" <tazmas...@rock etmail.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_inters ection. Something like:

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

Row
findCommonEleme nts(
Table::const_it erator
begin,
Table::const_it erator
end )
{
Row result ;
Table::const_it erator
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_inters ection(
tmp1.begin(), tmp1.end(),
tmp2.begin(), tmp2.end(),
std::back_inser ter( 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 objektorientier ter Datenverarbeitu ng
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...@rock etmail.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_inters ection. Something like:

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

Row
findCommonEleme nts(
Table::const_it erator
begin,
Table::const_it erator
end )
{
Row result ;
Table::const_it erator
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_inters ection(
tmp1.begin(), tmp1.end(),
tmp2.begin(), tmp2.end(),
std::back_inser ter( 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*******@rocke tmail.com
Jan 16 '08 #9

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

Similar topics

6
2698
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 deperation because when I defined it as char * insert(char table,int cols, char values)
16
4410
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
10205
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: > http://groups.google.com/group/comp.lang.c++/msg/db577c43260a5310?hl > >Another way is to create a one dimensional array and handle the >indexing yourself (index = row * row_size + col). This is readily >implemented in template classes that can create dynamically allocated >multi-dimensional...
8
2237
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
2298
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 that it will be evaluated like "x", just as "x" is evaluated like "x" right now.
6
2279
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 array into a subroutine, and inside it I "Redim Preserve" the array to increase the number of item in the array. I got the error "Redim statement requires an array", but arr is an array. HOw can I fix this problem ? Or, how can I do ArrayList for...
8
11829
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 way to do this is a nested for-loop - but we all know O(n^2) is bad. So I am looking for something like ArrayList.ToArray(), or Matlabs A(:). C#
272
14199
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 dimensional arrays from std::vectors ??? I want to use normal Array Syntax.
5
3887
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 different models of cars that are produced by the car manufacturer. Task 1 Step 1: Create a directory called Assignment02 and create the files of steps 2, 3 and 4 in this directory as well as your project file. Step 2: Create a file called...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.