• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Searching a 2d array

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Hope all are well, just have a few questions regarding searching through a 2d array and the different methods that could be used.

The problem i have is that the 2d array i have is full of objects, and each object may have a different time constraint for processing, so how i search the array is important.
I have started off attempting the normal start at the begining and work to the end type writer style search such as:


and the s shape style search, starting at the begining of column and work to the top, then move to next row and work from top of column to the beginning.


So now im just wondering can people recommend other search types with code examples, particulary i would like to search 2 rows of columns at the same time in the same loop and perhaps seach columns by going up and down rows opposed to left to right through columns etc.

All help and discussion appreciated.

Best
Mark Hughes
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The problem i have is that the 2d array i have is full of objects, and each object may have a different time constraint for processing, so how i search the array is important.


If each object in the array has a different time constraint for processing then how you search the array is irrelevant unless the objects are sorted in a particular order based on their time constraint.

If they are stored in some time order then you need to tell us what it is so we can suggest an appropriate algorythm.
If they are not in any order then the best approach would probably be to run through the array storing references to each object in an ordered queue (ordered on the time constraint). Then process each object in the queue in order. This way you guarantee the objects with the short time constraint get processd first.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,

Ultimatly the algorithm i have to use to search the array is the traveling salesman algorithim, As far as i know sorting the array is not an option and is not allowed to be used in the solution. When searching the array, and processing an object on the array, there is a flag variable that is set, depeding on the flag variable certain objects will take longer or shorter to process hence the time constrant but for the current excercies this is not really important i was just setting the scene as to why im learning 2d array searches

Im just starting off gettting to grips with the problem, so im looking to learn how to work with 2d arrays and multiple ways of searching them with basic searchs first, seacrhing by columns, rows, multiple columns at once etc to begin the learning process.

There is many other constraints etc involed with the problem, but as i said my only goal now is to work with basic 2darrays and multiple ways of searching / iterating through them. Any examples or web pages discussing 2d array searches would be great, as most things ive come accross so far have been just the type writer type search.

Best
Mark
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try googling for things like "traversing 2d Arrays" "iterating 2d Arrays".
Also there's a list of standard algorithms on wikipedia that may contain something of interest.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea ive been trying both methods, with out much luck in the code examples departemnt. All examples seem to stay at the very simpliest tansversly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic