1
Computer Science Foundation Exam
May 3, 2000
Section I A
No Calculators!
Name:
_______________________________
SSN:
________________________________
In this section of the exam, there are three (3) problems.
You must do all of them.
The weight of each problem in this section is indicated with the problem.
The algorithms in this exam are written in a combination of pseudocode, and
programming language notation.
Partial credit can not be given unless all work is shown.
If you need extra room to do work to be graded then do so on the last page
attached to this test. Make sure to clearly label the problem you are working on.
As always, be complete, yet concise, and above all be neat
,
credit can not be given when your results are unreadable.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
2
(1, 20%)
Given the following array of numbers and procedure, answer the questions below.
Assume that the global array
X[1..n]
is correctly declared and contains the values shown. (So
n=8.) Assume that all division(/) is integer division. So, for example, 17/3 evaluates to 5.
Array X
0
0
0
0
0
0
0
0
Position
1
2
3
4
5
6
7
8
procedure ArrayOperation(i, j: integer)
mid, k : integer;
mid
←
(i + j)/2;
for k
←
i to j do
if (k MOD 2 = 0) then
X[k]
←
X[k] + i
else
X[k]
←
X[k] + j
endif
endfor
if (mid > i) then
ArrayOperation(i, mid);
ArrayOperation(mid + 1, j);
endif
endprocedure
a)
(8 pts) Show the array
X
after the procedure call ArrayOperation(1,8) has executed?
Array X
14
3
16
5
22
11
24
13
Position
1
2
3
4
5
6
7
8
b)
(6 pts) Consider the case where each element of the array X is equal to m, where m is a
positive integer. Now consider executing the procedure ArrayOperation(1,8). What will the
sum of the elements of the array X be, in terms of m, after the procedure call?
Here, the values in the array will be m+14, m+3, m+16, m+5, m+22, m+11, m+24, and
m+13. These add up to 8m+108.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Computer Science, ObjectOriented Programming, ptr toa tree_node

Click to edit the document details