Algorithms & Programming unit test
A test on this unit alone, marked as a percentage and a letter grade — for the test your class is actually sitting, rather than for May. Answer everything, then submit once: seeing the answer to question 3 before attempting question 4 makes the final percentage meaningless.
Decidable vs undecidable
Variable
List indexing in AP pseudocode
Binary search
INSERT
REPEAT UNTIL
FOR EACH loop
Sequential computing
Undecidable problem
Nested conditional
NOT
Simulation
Short answer 1. Define or explain: Heuristic
3 ptsShort answer 2. Define or explain: Speedup
3 ptsShort answer 3. Define or explain: Algorithm
3 ptsShort answer 4. Define or explain: Why binary search needs a sorted list
3 ptsFree response
6 ptsA programmer writes the following procedure, intending it to return the number of values in a list that are greater than a given threshold. List indexes begin at 1. PROCEDURE countAbove(values, limit) { count ← 0 i ← 1 REPEAT UNTIL (i > LENGTH(values)) { IF (values[i] > limit) { count ← count + 1 } } RETURN(count) }
Trace the call countAbove([5, 12, 3], 4) and describe exactly what happens.
Identify the error and state the single change that fixes it.
After the fix, state what countAbove([5, 12, 3], 4) returns and what countAbove([1, 2], 9) returns.
Explain how you would test the corrected procedure to be confident it is right, and describe how the number of steps grows as the list gets longer.