This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Computer Science Foundation Exam August 17, 1999 - CS I section In this section of the exam, there are six (6) problems, some with multiple parts. You are to do all of them. The weight of each problem in this section, is indicated with the problem. The parts of a multi-part problem are equally weighted. The algorithms in this exam are written in a combination of pseudocode and programming language notation. The algorithms that you are asked to produce should use a syntax that is clear and unambiguous. Partial credit can not be given unless all work is shown. As always, be complete, yet concise, and above all be neat, credit can not be given when your results are unreadable. (1, 20%) Given the following array of numbers and the algorithm below, answer the questions below. Assume that the global array X[1..n] is correctly declared and contains the values shown. Array X 4 5 2 6 3 5 3 1 position 1 2 3 4 5 6 7 8 procedure M(a, b : integer) c, d, i, j : integer; c &lt;- 0; d &lt;- 0; i &lt;- a - 1; j &lt;- c + 1; while (i &gt; j) do if (X[i] &gt;= X[j]) then c &lt;- c + (X[i] - X[j]); j &lt;- j + 1; else c &lt;- c + (X[j] - X[i]); i &lt;- i - 1; endif if (X[i] &lt; b) then X[i] &lt;- X[i] + 1; else X[i] &lt;- X[i] - 1; endif d &lt;- d + X[j]; endwhile endprocedure a) Show the array X after the procedure was called with M(8,4) ? Array X...
View Full Document