aspose file tools*
The moose likes Java in General and the fly likes Searching a 2d array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Searching a 2d array" Watch "Searching a 2d array" New topic
Author

Searching a 2d array

Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
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
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1946
    
  28
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

Joined: Jul 14, 2006
Posts: 146
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

Joined: Aug 07, 2007
Posts: 1946
    
  28
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

Joined: Jul 14, 2006
Posts: 146
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching a 2d array
 
Similar Threads
Java Code
totaling array rows and columns
Vector within vector
Problem moving columns and rows in 2D array.
Two Dimensional Arrays