GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Computing x¹²⁷ by multiplication, where each step multiplies two powers already computed (squarings count as multiplications), what is the minimum number of multiplications needed (the length of a shortest addition chain for 127)?
- A. 12
- B. 11
- C. 13
- D. 10
Correct answer: D. 10
The binary method needs 6 squarings + 6 multiplications = 12. A shorter chain exists: 1, 2, 4, 8, 16, 32, 40, 42, 84, 126, 127 (10 steps), and an exhaustive search shows 9 steps are impossible. So the minimum is 10.
More Algorithms questions
- Euclid's algorithm gcd(a, b) repeatedly replaces (a, b) by (b, a mod b) until b = 0, counting one step per mod operation. Over all pairs 1…
- The Sieve of Eratosthenes on 2..100 crosses out the multiples of each prime p ≤ 10, starting from p² (p², p² + p, …). How many numbers are…
- The Tower of Hanoi with 6 disks is played on three pegs in a row (left, middle, right), and a disk may move only between adjacent pegs…
- Of the 92 solutions of the 8-queens problem (rotations and reflections counted separately), how many have no queen on either of the two…
- Four men m0–m3 and four women w0–w3 have preference lists (best first) m0: w1 w0 w2 w3; m1: w0 w2 w1 w3; m2: w1 w3 w2 w0; m3: w0 w1 w3 w2…
- For n = 5 distinct keys, let M be the worst-case comparisons of top-down merge sort (split ⌈n/2⌉ + ⌊n/2⌋, merge stops when one side is…