VOOZH about

URL: https://www.geeksforgeeks.org/dsa/stern-brocot-sequence/

⇱ Stern-Brocot Sequence - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Stern-Brocot Sequence

Last Updated : 7 May, 2021

Stern Brocot sequence is similar to Fibonacci sequence but it is different in the way fibonacci sequence is generated . 
Generation of Stern Brocot sequence :
 

1. First and second element of the sequence is 1 and 1.
2. Consider the second member of the sequence . Then, sum the considered member of the sequence and it's precedent i.e (1 + 1 = 2) . Now 2 is the next element of our series . Sequence will be [ 1, 1, 2 ]
3. After this element, our next element of the sequence will be the considered element of our second step. Now the sequence will be [ 1, 1, 2, 1 ]
4. Again we do the step 2, but now the considered element will be 2(3rd element ). So, next number of sequence will be sum of considered number and it's precedent (2 + 1 = 3). Sequence will be now [ 1, 1, 2, 1, 3 ]
5. Like step 3, the next element will be the considered element i.e 2 . Thus sequence will be [ 1, 1, 2, 1, 3, 2 ]
6. Hence this process continues, now next considered element will be 1( 4th element ) . 
 


 


Here is the simple program to print Stern Brocot sequence . 
 

Output: 
 

1 1 2 1 3 2 3 1 4 3 5 2 5 3 4


References : 
Github
 

Comment
Article Tags: