Data Structures & AlgorithmsVery hardTCS NQT · Infosys

Starting at n = 7, repeat: if n is even replace n by n/2, otherwise replace n by 3n + 1. How many steps are needed to reach 1?

  1. A. 16
  2. B. 17
  3. C. 18
  4. D. 20

Correct answer: A. 16

The sequence is 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, and counting its transitions gives 16. Counting the terms instead gives 17.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic