Open In App

GATE | GATE-CS-2015 (Set 3) | Question 59

Last Updated : 28 Jun, 2021
Like Article
Like
Save
Share
Report

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 ____________.
(A) 0
(B) 1
(C) 2
(D) 3


Answer: (A)

Explanation:

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 ____________.

For i = 0, z = 1 mod 8 = 1, since c[0] = 1, z = 1*2 mod 8 = 2.

For i = 1, z = 2*2 mod 8 = 1, since c[1] = 0, z remains 4.

For i = 2, z = 16 mod 8 = 0 

Once z becomes 0, none of the statements inside DOSOMETHING() can make it non-zero.


Quiz of this Question


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads