edited by
2,103 views
3 votes
3 votes

Consider the following pseudo-code fragment in which an invariant for the loop is “ $m ^*x^k=p^n$ and $k \geq 0$ ” (here, $p$ and $n$ are integer variable that have been initialized):

/* Pre-conditions : $p \geq 1 \wedge n \geq 0$ */

/* Assume that overflow never occurs */

int $x=p$; int $k=n$; int $m=1$;

while $(k < >0)$ {

if (k is odd) then $m=m^*x$;

$x=x^*x$;

$k=\lfloor k/2 \rfloor$;       /* floor$(k/2)$ */

}

Which of the following must be true ar the end of the while loop?

  1. $x=p^n$
  2. $m=p^n$
  3. $p=x^n$
  4. $p=m^n$ 
edited by

1 Answer

0 votes
0 votes

This pseudo code basically represents the exponentiation algorithm. With p as the base and n as the power and the final result is stored in m.

Answer : B

Answer:

Related questions

2 votes
2 votes
2 answers
3
Arjun asked Jul 2, 2019
7,072 views
How many ways are there to place $8$ indistinguishable balls into four distinguishable bins?$70$$165$$^8C_4$$^8P_4$
3 votes
3 votes
2 answers
4
Arjun asked Jul 2, 2019
5,758 views
How many bit strings of length ten either start with a $1$ bit or end with two bits $00$ ?$320$$480$$640$$768$