I have and array that can take any number of points, and the points are given an index.
Then I am running a non recursive solution that creates all permutations
It runs through 1,2,3,4,5,6,7,8,9,0
and ends with 0,9,8,7,6,5,4,3,2,1
this has a time complexity to it
Now, I would like to find the middle point of these permutations so that I can run the pattern from the start and the middle with threads to reduce the time complexity.
How would I find the middle point?.
In Java:
public Path QuickPerm(int[] points) {
int N = points.length;
int a[] = points ;
int p[] = new int[N];
Path shortest = null;
Path current = null;
int i;
int j;
int tmp; // Upper Index i; Lower Index j
for(int i1 = 0; i1 < N; i1++) {
p[i1] = 0; // p[i] == i controls iteration and index boundaries for i
}
//display(a, 0, 0); // remove comment to display array a[]
i = 1; // setup first swap points to be 1 and 0 respectively (i & j)
while(i < N) {
if (p[i] < i) {
j = i % 2 * p[i]; // IF i is odd then j = p[i] otherwise j = 0
tmp = a[j]; // swap(a[j], a[i])
a[j] = a[i];
a[i] = tmp;
//save
p[i]++; // increase index "weight" for i by one
i = 1; // reset index i to 1 (assumed)
} else { // otherwise p[i] == i
p[i] = 0; // reset p[i] to zero
i++; // set new index value for i (increase by one)
} // if (p[i] < i)
}
return shortest;// while(i < N)
} // QuickPerm()