Pseudo Code: Programming On Paper For Ib Paper 1 Exams
Pseudo Code: Programming On Paper For Ib Paper 1 Exams
8 pages 3 pages
NOT given in exam Given in exam
Warning!
Pseudo code questions are never as overt or obvious
as the examples we discuss in these sessions.
These examples are only there to teach you the skills
you need to answer more complex problems.
You get marks for individual sections, not the final output.
This means you could well get 7/8 even if your final output is not right.
T1: Array based method
Given an array of ints of odd length, look
at the first, last, and middle values in
the array and return the largest. The array
length will be a least 1.
maxTriple([3]) → 3
maxTriple([1, 5, 3]) → 5
maxTriple([1, 9, 5, 8, 3]) → 5
T2: Array counting
Given an array of ints, return the sum of the
first 2 elements in the array. If the array
length is less than 2, just sum up the elements
that exist, returning 0 if the array is length
0.
sum2([]) → 0
sum2([1, 1]) → 2
sum2([1, 1, 1, 1]) → 2
T3: Fix34 problem
Return an array that contains exactly the same
numbers as the given array, but rearranged so that
every 3 is immediately followed by a 4. Do not move
the 3's, but every other number may move. The array
contains the same number of 3's and 4's, every 3 has
a number after it that is not a 3, and a 3 appears
in the array before any 4.