This preview shows pages 1–3. Sign up to view the full content.
October 16
th
Foundation Exam
CS I Questions
(1, 15%)
The following (INCORRECT) algorithm is intended to be the iterative bubble sort algorithm.
Assume that
swap
is a global procedure that exchanges the contents of its two parameters.
algorithm Bsort(n)
procedure B(k)
1) set j < 1
2) while j < k do
3) if a[j] > a[j+1] then
4) swap(a[j], a[j+1])
5) set j ß j + 1
endprocedure
begin
6) for i = 1 to n1 do
7) B(ni);
endalgorithm
It SHOULD take this first list…
8
3
10
7
5
4
…and produce this list.
3
4
5
7
8
10
1a)
But, it doesn't. What does it produce?
1b)
There is one error in the algorithm. In which line does it occur? __________
1c
) Write the correct pseudocode for the line identified in 1b).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document(2, 20%)
The following are Postfix strings. All values are single decimal digits and the operations are binary
add "+", binary subtract "",and binary multiplication "*".
Indicate which are invalid, if any. For those that are valid, compute the result.
a)
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 Staff
 Bubble Sort

Click to edit the document details