GateAI
Algorithm Design Techniques

GATE CSE 2015 Set 3 · Q49

NAT2 marksEasy

Time

Suppose c=⟨c[0],...,c[k−1]⟩c = \langle c[0], ..., c[k - 1]\rangle is an array of length kk, where all the entries are from the set {0,1}\{0, 1\}. For any positive integers aa and nn, consider the following pseudocode.DOSOMETHING (c, a, n) z ← 1 for i ← 0 to k - 1 do z ← z^2 mod n if c[i] = 1 then z ← (z × a) mod n return zIf k=4,c=⟨1,0,1,1⟩,a=2k = 4, c = \langle 1, 0, 1, 1\rangle, a = 2 and n=8n = 8, then the output of DOSOMETHING(c,a,n)(c, a, n) is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 0

Algorithm Design Techniques

We can trace the execution of DOSOMETHING(c, a, n) with k=4k = 4, c=⟨1,0,1,1⟩c = \langle 1, 0, 1, 1 \rangle, a=2a = 2, and n=8n = 8:

  • Initially:

    z=1z = 1
  • Iteration i=0i = 0 (c[0]=1c[0] = 1):

    • z←z2 mod 8=12 mod 8=1z \leftarrow z^2 \bmod 8 = 1^2 \bmod 8 = 1

    • Since c[0]=1c[0] = 1: z←(z×a) mod 8=(1×2) mod 8=2z \leftarrow (z \times a) \bmod 8 = (1 \times 2) \bmod 8 = 2

  • Iteration i=1i = 1 (c[1]=0c[1] = 0):

    • z←z2 mod 8=22 mod 8=4z \leftarrow z^2 \bmod 8 = 2^2 \bmod 8 = 4

    • Since c[1]=0c[1] = 0, the if condition is false.

  • Iteration i=2i = 2 (c[2]=1c[2] = 1):

    • z←z2 mod 8=42 mod 8=16 mod 8=0z \leftarrow z^2 \bmod 8 = 4^2 \bmod 8 = 16 \bmod 8 = 0

    • Since c[2]=1c[2] = 1: z←(z×a) mod 8=(0×2) mod 8=0z \leftarrow (z \times a) \bmod 8 = (0 \times 2) \bmod 8 = 0

  • Iteration i=3i = 3 (c[3]=1c[3] = 1):

    • z←z2 mod 8=02 mod 8=0z \leftarrow z^2 \bmod 8 = 0^2 \bmod 8 = 0

    • Since c[3]=1c[3] = 1: z←(z×a) mod 8=(0×2) mod 8=0z \leftarrow (z \times a) \bmod 8 = (0 \times 2) \bmod 8 = 0

After all iterations, the returned value of zz is 0.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Algorithm Design Techniques previous year question is Q49 of the GATE CSE 2015 Set 3 paper. Find more GATE CSE PYQs on Algorithm Design Techniques in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Algorithm Design Techniques PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Algorithm Design Techniques in GATE CSE

Algorithm Design Techniques has 6 GATE CSE PYQs across 6 papers from 2011 to 2017. 3 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2015 Set 3.

How GATE tests Algorithm Design Techniques

More from GATE CSE 2015 Set 3

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2015 Set 3 · Q49 · NAT

Suppose c = c[0], ..., c[k - 1] is an array of length k, where all the entries are from the set {0, 1}. For any positive integers a and n, consider the following pseudocode. DOSOMETHING (c, a, n) z ← 1 for i ← 0 to k - 1 do z ← z2 mod n if c[i] = 1 then z ← (z × a) mod n return z If k = 4, c = 1, 0, 1, 1 , a = 2 and n = 8, then the output of DOSOMETHING(c, a, n) is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.