Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 31st, 2006, 04:05 PM
Adrastea0413's Avatar
Adrastea0413 Adrastea0413 is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2003
Location: Washington, DC Metro
Posts: 1,742 Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level)Adrastea0413 User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 20 h 28 m 9 sec
Reputation Power: 804
Facebook
Algorithm help - boolean operations on array elements

Okay, say I have a 2D array like the following:

Array [0][0] = "Fruit"
Array [0][1] = "Apple"
Array [0][2] = true

Array [1][0] = "Fruit"
Array [1][1] = "Apple"
Array [1][2] = true

Array [2][0] = "Fruit"
Array [2][1] = "Apple"
Array [2][2] = false

Array [3][0] = "Fruit"
Array [3][1] = "Pear"
Array [3][2] = true

Array [4][0] = "Fruit"
Array [4][1] = "Pear"
Array [4][2] = true

As you can see, the [n][0] element is a broad descriptor of the [n][1] element. I'm trying to think of an algorithm that will take the [n][2] element for each like [n][1] element and "AND" them. Then take the "AND" values for each [n][1] element and "OR" them. Since [3][1] and [4][1] both equal "Pear", the [3][2] and [4][2] elements would be "AND"-ed together, in this case, returning "true". So the "Pear" value of "Fruit" would be true.

The same would happen for Apple, but Apple would be false, since it does not satisfy the AND requirements.

Then, because Pear is true and Apple is false, the algorithm would return true for "Fruit" because it meets the OR requirement.

Are there any popular algorithms that are similar to this? I don't kow of any, but I figured someone else might.

Thanks.

Reply With Quote
  #2  
Old January 31st, 2006, 04:51 PM
CountVikernes's Avatar
CountVikernes CountVikernes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Lisbon, Portugal
Posts: 154 CountVikernes User rank is Corporal (100 - 500 Reputation Level)CountVikernes User rank is Corporal (100 - 500 Reputation Level)CountVikernes User rank is Corporal (100 - 500 Reputation Level)CountVikernes User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 14 h 37 m 54 sec
Reputation Power: 7
I might be completely off, but... in the end, aren't you just checking if there is a FALSE in every [n][1] category for the specified [n]?

Working backwards, for the OR to work out TRUE, it means that at least ONE of the categories "inside" [n][0] ("fruits" or "vegetables") has to be true.

For this statement to be true, it means that at least ONE of the sub-categories ("apple", "pear", ...) has to have a full completement of [n][2] as TRUE.

You could simply iterate over the array, checking every category for at least one FALSE. If there was one category you had failed to find the FALSE in, then it meant the answer was true, and you didn't have to continue running through the array. On a similar note, whenever you found a "FALSE" in a category, you could skip it entirely.



Also, it might be worth checking out if making an array with more "dimensions" makes any sense, or if re-arranging data organization is more trouble than it's worth or not.

It depends on how you retrieve that information, but I'm guessing you could build an array along the lines of:

Code:
myArray =
   ["Fruit"] =
      ["Pear"] = [true, true, false, true, false, ...]
      ["Apple"] = [false, false, true, false, true, true, ...]
   ["Veggies"] =
      ["Cabbage"] = [true, ...]
      ["Onions"] = [false, ...]


You've got the point. In any case, it makes for an easier algorithm to solve that problem you're looking at. Well, maybe not easier, but I'm guessing at least cleaner and clearer.

Hope that made sense. Again, I might be completely off:\
__________________
"Get it hot! Hit it harder!!!"
--- The tutor warcry

ActivePython
Mark Pilgrim's Dive into Python E-book, thank this guy for his contribution to the Python community!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Algorithm help - boolean operations on array elements


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT