Consider an algorithm that uses only assignment statements that replaces the quadruple (w, x, y, z) with (x, y, z, w). What is the minimum number of assignment statements needed?

Respuesta :

Answer:

The minimum number of assignment statements needed is 5

Step-by-step explanation:

To write the algorithm, we apply the strategy of interchanging the values of variables in the assignment statements.

Assume "tmp" is the new variable, let assign tmp to w

The algorithm is:

Procedure exchange (w,x,y,z: integers)

 tmp := w

    w := x

     x := y

     y := z

     z := tmp

    return (w,x,y,z)

end

From the algorithm, it is obvious that there will be a minimum of 5 assignment statements needed.

ACCESS MORE