Pseudo Code
PROGRAMMING ON PAPER FOR IB PAPER 1 EXAMS
SESSION 3
2 official pseudo code guides
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.
Topics 4, 5 and 7 can include pseudo code…
Top pseudo code tips
When possible, start answering a pseudo code question at the top of a page
Write pseudo code in pencil first and then copy into pen
Think about the data types and associated access methods BEFORE writing
anything
Think about what control structures (especially loops) are associated with that
data type
Be sure to return or output something at the end of the problem – even if they
don’t ask for it!
Basic structure of ALL pseudo code questions
Declarations / Initialisations
Control structures / Calculations
Output / Return
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.
fix34([1, 3, 1, 4]) → [1, 3, 4, 1]
fix34([1, 3, 1, 4, 4, 3, 1]) → [1, 3, 4, 1, 1, 3, 4]
fix34([3, 2, 2, 4]) → [3, 4, 2, 2]
T4: Position of smallest element in 2D array
A 2D array called M of
10 columns and 8 rows is
created and filled with
random unique integers.
Return the location in
the format COL, ROW of
the smallest integer in
the array.