algorithms.tutorialhorizon.com

Minimum No of operations required to convert a given number to 1 - Integer Replacement Problem. | Algorithms

Objective: Given a number N, write an algorithm to convert that number to 1. Below are the allowed operations. If N is even, do N = N/2. If N is odd, either do N =N - 1 or do N = N + 1 Example: N = 16 Output: 4 16 → 8 → 4 → 2 → 1