Like Fibonacci numbers, a Fibonacci word. is a specific sequence of binary digits (or symbols from any two-letter alphabet). The Fibonacci word is formed by repeated concatenation in the same way that the Fibonacci numbers are formed by repeated addition. But unlike the fibonacci number, Fibonacci word has its first two terms different from each other.
In Fibonacci word, S(0) = 0, S(1) = 01, S(2) = 010, S(3) = 01001 ..... where S(n) = S(n-1) + S(n-2) and + represents the concatenation of strings.
The task is to find nth Fibonacci word for a given number n.
Input : n = 4 Output : S(4) = 01001010 Input : n = 2 Output : S(2) = 010
Just like in program of Fibonacci number, we use the iterative concept of finding nth Fibonacci number here for finding nth Fibonacci word we can use the iterative concept. So for finding n-th Fibonacci word we will take two string Sn and Sn_1 which represent S(n) and S(n-1) respectively and on each iteration we will update tmp = Sn, Sn = Sn + Sn_1 and Sn_1 = tmp in this way we can find nth fibonacci word.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Longest Common Prefix using Word by Word Matching
- C program to find and replace a word in a File by another given word
- C program to Replace a word in a text by another given word
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Check if a M-th fibonacci number divides N-th fibonacci number
- Tribonacci Word
- Minimum Word Break
- Encoding a word into Pig Latin
- Second most repeated word in a sequence
- Possibility of a word from a given set of characters
- Next word that does not contain a palindrome and has characters from first k
- Length Of Last Word in a String
- Program to find the Encrypted word
- Reverse every word of the string except the first and the last character
- Second most repeated word in a sequence in Python
- Print last character of each word in a string
- Capitalize the first and last character of each word in a string
- Remove the first and last character of each word in a string
- Check if a word is present in a sentence
- Print the first and last character of each word in a String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.