# aug17-99 - Computer Science Foundation Exam August 17, 1999...

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
This is the end of the preview. Sign up to access the rest of the 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 &amp;lt;- 0; d &amp;lt;- 0; i &amp;lt;- a - 1; j &amp;lt;- c + 1; while (i &amp;gt; j) do if (X[i] &amp;gt;= X[j]) then c &amp;lt;- c + (X[i] - X[j]); j &amp;lt;- j + 1; else c &amp;lt;- c + (X[j] - X[i]); i &amp;lt;- i - 1; endif if (X[i] &amp;lt; b) then X[i] &amp;lt;- X[i] + 1; else X[i] &amp;lt;- X[i] - 1; endif d &amp;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

## aug17-99 - Computer Science Foundation Exam August 17, 1999...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online