wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Array searching and scoring? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array searching and scoring?" Watch "Array searching and scoring?" New topic
Author

Array searching and scoring?

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Suppose I have an array of integers:

int[] numbers = [2,2,1,1,2,2,1,1,2,1]

These integers index originate from another array:

int[] primaryKey = [1, 2]

Now, an ideal situation for me would be if all numbers of the same value are next to each other in the array. e.g.

int[] numbers = [1,1,1,1,1,2,2,2,2,2]

So, in order to determine how 'good' the array is, I need to create a score the array depending on how well they are positioned, using the following rules (assume 'counter' and 'score' begin at 0):


Find first/next position of occurence of primaryKey[counter]

if next integer is the same then score = score + 3
repeat until end of repated integers found

Find next position of occurence of primaryKey[i], until end of array is reached and repeat the above. In which case...

if no more primaryKey[i] is found in array, then increment i to move onto the next element in the primaryKey array and see how badly this next integer under examination is scattered around the array using the rules above.



I have been trying to figure this out but I just can't. Can anyone help me please?
[ February 22, 2006: Message edited by: Sam Bluesman ]

Moosey knows best
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Just to be sure I understand the question , would the "score" of the "ideal array in your example be 24?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Not sure what why you are adding 3 to the score for a good pair of numbers.

My 2 minute first cut at sudo code


Please ignore post, I have no idea what I am talking about.
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
24, that is correct
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Cheers William. Most helpful.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Three questions...
  • Does order matter? In particular, should {2,2,2,1,1,1} be considered as "good" as {1,1,1,2,2,2}? If I'm understanding this, these would score the same.
  • Are all of these arrays the same length? If not, the score should be standardized for length.
  • On a related note, do these arrays all contain the same number of unique elements? For example, do they all contain just 1's and 2's? Or might some also contain 3's, 4's, etc? This would also need to be standardized, since the first occurrence doesn't add to the score.
  • Also, I'm not convinced about this approach. I understand that you want to quantify the degree to which an array corresponds to a desired order or "grouping." But I don't understand what this score actually means, because I think this depends on what you need to do with the arrays. For example, do you simply discard low-scoring arrays? Or do you need to "fix" them (which I assume has implications beyond mere sorting)? And if you're fixing them, are these scores actually representative of the amount of "work" required? In other words, what is this score really telling you?
    [ February 23, 2006: Message edited by: marc weber ]

    "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: Array searching and scoring?