I had an exam in algorithms today and we had the following task. I didn't really solve it, but know I am really interested how it works.
Task: We have a bit vector s and we want to know if there are triples in the vector, so if 1 stands in Index i, j, k then k-j = j-i
Example: [0,1,0,0,1,0,0,1], i = 1 , j = 4, k = 7
I have solved the problem for an algorithm in O(n^2), so we have two loops, in the outer loop we search for the first 1, in the inner loop we search for the index of j and then we calculate the index of k with i and j and check, if on the index of k is a 1 too.
But it should be an algorithm in O(nlog(n)). We had the hint, that we can use x^i x^k = x^k x^i for the algorithm in O(nlog(n)). Has anyone an idea, how to solve the problem in O(nlog(n))?