CS1121400s - Computer Science Foundation Exam December 14,...

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

View Full Document Right Arrow Icon
Computer Science Foundation Exam December 14, 2000 Section I A Solutions
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 862745 position 123456 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 ± j ± endif exitif (i > 5) OR (j = 1) endloop endprocedure a) Show the array X after the procedure has completed execution? Array X 31274 1 0 position b) What value will the following variables contain after the loop is finished? a 23 b 10 c 20 d 26
Background image of page 2
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).
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2011.

Page1 / 6

CS1121400s - Computer Science Foundation Exam December 14,...

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

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