Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is an infinite binary sequence of 0s and 1s. The sequence is obtained by starting with 0 and successively appending the Boolean complement of the sequence obtained so far.
First few steps :
Start with 0
Append complement of 0, we get 01
Append complement of 01, we get 0110
Append complement of 0110, we get 01101001
Given a whole number n. The task is to find the nth string formed of by Thue–Morse sequence i.e prefix of length 2n-1 of Thue–Morse sequence.
Input : n = 4 Output : 01101001 We get 0, 01, 0110 and 01101001 in fourth iteration. Input : n = 3 Output : 0110
The idea is to initialize the output string with 0, then run a loop n – 1 times and for each iteration find the complement of the string and append it to the string.
Below is implementation of this approach:
- Convert an unbalanced bracket sequence to a balanced sequence
- Sum of the sequence 2, 22, 222, .........
- Look-and-Say Sequence
- Gould's Sequence
- De Bruijn sequence | Set 1
- Aronson's Sequence
- Connell Sequence
- Find F(n) when F(i) and F(j) of a sequence are given
- Increasing sequence with given GCD
- Alcuin's Sequence
- Gijswijt's Sequence
- Aliquot Sequence
- k-th number in the Odd-Even sequence
- Padovan Sequence
- Recaman's sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.