## Recaman's SequenceRecamán's sequence recurrence relation in mathematics and computer science. Because its elements are clearly related to the previous elements, they are frequently defined using recursion. ## Definition
0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155, ...
It is essentially a function with domain and co-domain as natural numbers and 0 respectively. It is defined recursively as follows: Make a(n) to denote the (n+1)-th term. (0 is already present).
A simple implementation is shown below, in which we store all n Recaman Sequence numbers in an array. Using the recursive formula mentioned above, we compute the next number. ## C++
0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, **Time Complexity :**O (n^{2})**Auxiliary Space :**O (n)
## C++
0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, **Time Complexity :**O(n)**Auxiliary Space :**O(n)
## UsesRecamán's sequence, in addition to its mathematical and aesthetic properties, can be used to encrypt 2D images using steganography. |

For Videos Join Our Youtube Channel: Join Now

- Send your Feedback to [email protected]