For this Algorithm assignment in class I have to find all the unique values in a 1000x250 2D array.
The data is between 2000000 to 2200000. All the data is stored in a 2D int array called data.
The problem I am having is that it takes a bit of time to run this and my prof said we can't use other data sets and also we need to optimize our code so it runs at a good speed.
int[] uniqueValues = new int[200000];
boolean isUnique = true;
int uniqueCounter = 0;
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
for (int x = 0; x < uniqueCounter; x++) {
if (data[i][j] != uniqueValues[x]) {
isUnique = true;
} else {
isUnique = false;
break;
}
}
if (isUnique) {
uniqueValues[uniqueCounter] = data[i][j];
uniqueCounter++;
}
}
}