Starting with any positive integer N, we define the Collatz sequence corresponding to N as the numbers formed by the following operations:

N → N/2 ( if N is even) N → 3N + 1 (if N is odd) i.e. If N is even, divide it by 2 to get N/2. If N is odd, multiply it by 3 and add 1 to obtain 3N + 1.

It is conjectured but not yet proven that no matter which positive integer we start with; we always end up with 1.

For example, 10 → 5 → 16 → 8 → 4 → 2 → 1

A Coding Practice Question on Collatz Sequence

If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program to print Collatz Sequence
- Maximum Sequence Length | Collatz Conjecture
- GFact 22 | (2^x + 1 and Prime)
- GFact 23 | (Brocard’s problem)
- Program to implement Collatz Conjecture
- Count Possible Decodings of a given Digit Sequence
- Farey Sequence
- Find maximum length Snake sequence
- Construction of Longest Increasing Subsequence(LIS) and printing LIS sequence
- Complete the sequence generated by a polynomial
- Juggler Sequence
- Padovan Sequence
- Aliquot Sequence
- Maximum sum Bi-tonic Sub-sequence
- Recaman's sequence
- Largest sum Zigzag sequence in a matrix
- Minimum number of deletions to make a sorted sequence
- Thue-Morse sequence
- Sum of the sequence 2, 22, 222, .........
- Sylvester's sequence