CS1081800 - Computer Science Foundation Exam August 18,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
4 Computer Science Foundation Exam August 18, 2000 Solution for CS 1 sections (1, 20%) Given the following array of numbers and algorithm, answer the questions below. Assume that the global array X[1. .n] is correctly declared and contains the values shown. Assume that the procedure was called with S(1, 6). Array X 4 5 2 6 3 5 position 1 2 3 4 5 6 procedure S(i, j : integer) a, b, y, z : integer a 0 b 0 y 0 z 0 while (i < j) do if (X[i] < X[j]) then z z + j X[i] X[i] + i i i + 1 y y + X[i] else y y + i X[j] X[j] + j z z + X[j] j j - 1 endif if (a <= b) then a X[i] else b X[j] endif endwhile endprocedure a) Show the array X after the procedure has completed execution? Array X 5 7 5 6 8 11 position 1 2 3 4 5 6 b) What value will the following variables contain after the while loop is finished? a 6 b 6 y 17 z 33
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5 (2, 14%) The following are Postfix expressions. All values are single decimal digits and the operations are addition "+", subtraction "–", multiplication "*" and division “/”. In each box below the Postfix expression, show ONLY the contents of the stack at the indicated point in the Postfix string (point A, B or C). Put the final answer in the blank. If the Postfix string is invalid, carry the operations as far as possible and write “invalid” as
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

CS1081800 - Computer Science Foundation Exam August 18,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online