{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# CS1121400s - Computer Science Foundation Exam Section I A...

This preview shows pages 1–4. Sign up to view the full content.

Computer Science Foundation Exam December 14, 2000 Section I A Solutions

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

View Full Document
1 (1, 20%) Given the following array of integers 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 P1(1, 6, 5). Array X 8 6 2 7 4 5 position 1 2 3 4 5 6 procedure P1(i, j, k : integer) a, b, c, d : integer a 0 b 0 c 0 d 0 loop if (X[i] > X[j]) then a a + (X[i] - X[j]) X[i] X[i] - k c c + X[i] i i + 1 else if (X[j] > X[i]) then b b + (X[j] - X[i]) X[j] X[j] + k d d + X[j] j j - 1 else c c + k d d - k i i + 1 j j - 1 endif exitif (i > 5) OR (j = 1) endloop endprocedure a) Show the array X after the procedure has completed execution? Array X 3 1 2 7 4 10 position 1 2 3 4 5 6 b) What value will the following variables contain after the loop is finished? a 23 b 10 c 20 d 26
2 (2, 14%) In the following Postfix expressions all values are single decimal digits and the operations are addition "+", subtraction "–", multiplication "*" and division “/”. In each box below the Postfix expression in part a) , show ONLY the contents of the stack at the indicated point in the Postfix string (point A, B or C).

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.

{[ snackBarMessage ]}

### Page1 / 6

CS1121400s - Computer Science Foundation Exam Section I A...

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

View Full Document
Ask a homework question - tutors are online