Given two binary strings of length n, the brute-force method for determining if they are equivalent is just iteratively cycling one of them n times and comparing to see if the other string is ever obtained. Is there a faster algorithm? Perhaps there is a list of invariants that are fast to compute and uniquely determine the necklace? Or perhaps through a bijection with some other set, like the irreducible polynomials over F_2 with degree dividing n, it is possible to more efficiently solve the problem and transfer back?

obojeneqk

obojeneqk

Answered question

2022-09-13

Determining when two binary strings represent the same necklace or when one binary string is periodic
An equivalence relation on binary strings calls two strings equivalent if one can be obtained from the other by a cyclic permutation of the characters. Combinatorialists call the equivalence classes of such strings "necklaces".
Given two binary strings of length n, the brute-force method for determining if they are equivalent is just iteratively cycling one of them n times and comparing to see if the other string is ever obtained. Is there a faster algorithm? Perhaps there is a list of invariants that are fast to compute and uniquely determine the necklace? Or perhaps through a bijection with some other set, like the irreducible polynomials over F 2 with degree dividing n, it is possible to more efficiently solve the problem and transfer back?
A related question: is there an algorithm better than iterative cycling and comparison to get a computer to recognize if a string is periodic? That is, is there a fast algorithm to compute the stabilizer subgroup of a string under the action of the cyclic group of order n?

Answer & Explanation

Makhi Adams

Makhi Adams

Beginner2022-09-14Added 13 answers

Step 1
If you really wanted to you could get worst-case O(nlogn) using a fast fourier transform, at least when n is a power of 2.
I know nothing about such things, but I doubt that this could be worth the trouble, because it seems to me that the brute-force approach is going to be O(n) on average. Because you can compare two random strings of arbitrary length in constant average time:
Step 2
The probability you get a "no" after looking at the first character is 1/2. The probability that you have to look at the first and then the second characters to get a "no" is 1/4. And so on; the expected value of the number of character comparisons needed is no larger than
k = 1 k 2 k < .

Do you have a similar question?

Recalculate according to your conditions!

New Questions in College Statistics

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?