The GATE Grind

GATE 2015 CS (CS3) – Question 63

Algorithms · Divide-and-Conquer · 2 marks · Numerical answer

Find DOSOMETHING(c,a,n) for k=4,c=(1,0,1,1),a=2,n=8.

z=1
for i=0 to k−1:
  z=z² mod n
  if c[i]==1: z=(z*a) mod n
return z

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 0

Explanation

Start z=1. At i=0, square then multiply by two, yielding two. At i=1, square to four with no multiply. At i=2, square four modulo eight to zero, then multiply, remaining zero. The final iteration also leaves zero. Thus the returned value is zero.

More Divide-and-Conquer questions

All Divide-and-Conquer questions →