oct16cs1

oct16cs1 - October 16th Foundation Exam CS I Questions (1,...

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

View Full Document Right Arrow Icon
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 n-1 do 7) B(n-i); 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 pseudo-code for the line identified in 1b).
Background image of page 1

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

View Full DocumentRight Arrow Icon
(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)
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 / 6

oct16cs1 - October 16th Foundation Exam CS I Questions (1,...

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