IB Computer Science Past Papers & Drilling (Paper 2): Tracing, Binary Search and OOP
- 2026-10-24
TUTORZONE ORIGINAL DRILLING MOCK · IB COMPUTER SCIENCE PAPER 2 (2027 SYLLABUS, THEME B)
Written to the IB 2027 syllabus: Paper 2 (Theme B, computational thinking and problem solving) is 1 h 15 min, 50 marks, 35% at SL; HL is 2 hours, 80 marks, 40%. Programming questions come in both Python and Java versions and you answer in the language you were taught; HL adds OOP and abstract data types. The old Paper 3 has been removed. This is a Paper 2 drilling mock: 6 questions for 50 marks with worked answers.
What is in IB Computer Science Paper 2?
Direct answer: 2027 syllabus Theme B (computational thinking and problem solving) – SL 1 h 15 min, 50 marks, 35%; HL 2 hours, 80 marks, 40%. The scope is B1 computational thinking, B2 programming and B3 OOP, with B4 abstract data types at HL.

Assessment at a glance (2027)
| Component | Content | Weighting | Duration |
|---|---|---|---|
| Paper 2 (Theme B) | B1 computational thinking + B2 programming + B3 OOP; SL 50 marks (HL 80) | SL 35%/HL 40% | SL 1 h 15 min / HL 2 h |
| Paper 1 (Theme A + case study) | A1-A4 concepts + case study; SL 50 marks (HL 80) | SL 35%/HL 40% | SL 1 h 15 min / HL 2 h |
| Internal assessment (computational solution) | a computational solution to a self-chosen problem | SL 30%/HL 20% | 35 hours |
IB Computer Science Paper 2 drilling technique: do the B1 question that needs no code first (about 22 minutes), stating steps, inputs, outputs and edge cases in words; B2 wants runnable code (marks sit in variables, loops, selection and return), and if the question forbids built-ins, do not reach for sort(); B3 needs attributes, methods and a reason for encapsulation. Every programming question exists in Python and Java – answer in the language you were taught.
How this paper was built
This is a TutorZone original drilling mock: the questions follow the IB Computer Science Paper 2 format (2027 syllabus, Theme B), and all code and answers are our own – not IB past papers, marking references or IB publications.
Every numerical answer (trace total, comparison counts, mean, balances) was recomputed programmatically.
Pacing
| Section | Marks | Suggested time | What to do first |
|---|---|---|---|
| Paper 2 (Theme B) | SL 35%/HL 40% | about 20 min B1, 20 min B2, 30 min B3 | B1 algorithmic thinking first, code and OOP after |
| Paper 1 (Theme A + case study) | SL 35%/HL 40% | about 55 min Section A, 20 min Section B | concepts + case study analysis |
| Internal assessment (computational solution) | SL 30%/HL 20% | run it alongside Papers 1 and 2, not at the end | design, develop, evaluate |
Does Paper 2 require writing code, and in which language?
Direct answer: yes. Paper 2 requires programming, and the IB issues both a Python and a Java version of every programming question – answer in the one your school teaches; the mark scheme is the same.
Paper 2: Theme B (B1 algorithmic thinking 15 + B2 programming 15 + B3 OOP 20)
All compulsory; aim for 70 minutes with 5 to check. Answer code in either Python or Java.
Question 1 (8 marks)
Trace the code fragment, state the output and list the value of total after each loop iteration.
values = [4, 9, 2, 7, 5]
total = 0
for i = 0 to 4
if values[i] > 5 then
total = total + values[i] * 2
else
total = total + values[i]
end if
next i
output total
Question 2 (7 marks)
Sorted list data = [3, 8, 12, 17, 21, 26, 31, 35, 40, 44, 49, 53, 58, 62, 67]. (a) Search for 53 with binary search: give each midpoint compared and the number of comparisons. (4) (b) How many comparisons would a linear search need for 53 in the worst case? (3)
Question 3 (8 marks)
Write a function average_and_count(scores) that returns the mean score rounded to one decimal place, and the number of scores that are greater than or equal to the mean.
scores = [68, 54, 91, 47, 76, 83, 59]
(a) Write the function (4). (b) State its return values (4).
Question 4 (7 marks)
text = “Computer Science”. (a) Write a function that returns the number of vowels (a, e, i, o, u, case-insensitive) (4). (b) State how many uppercase letters the string contains and explain why case must be normalised before comparing (3).
Question 5 (10 marks)
Design a single class BankAccount. (a) List two attributes and three methods, and say which attribute is private and why (6). (b) The balance is 500; then deposit 250, withdraw 900, withdraw 180. Give the balance after each operation and explain why the 900 withdrawal is rejected (4).
Question 6 (10 marks)
A class Library keeps book titles in a list shelf with methods add(title), remove(title) and count(). (a) Show how remove(title) can handle the case where the title is absent (4). (b) After add(“A”), add(“B”), add(“C”) and remove(“B”), state the contents of shelf and what count() returns (3). (c) Explain why keeping shelf private is safer than letting outside code edit the list directly (3).
Does the B1 algorithmic-thinking question need code?
Direct answer: no. B1 asks for algorithmic thinking without code: inputs, steps, outputs and edge cases in words or a flowchart, then an evaluation of efficiency (linear O(n) against binary O(log n)).
Paper 2 answers and marks
Question 1
Iteration trace (1 mark each): total goes 4 -> 22 -> 24 -> 38 -> 43; output 43. The trap is iterations 2 and 4: 9 and 7 are greater than 5, so they are doubled before adding.
Question 2
(a) Index 0-14: midpoint index 7 = 35 (53 > 35, discard the left half); new range 8-14, midpoint index 11 = 53, found – 2 comparisons in total (1 each, 1 for the answer). (b) A linear search needs at most 15 comparisons (every element checked; worst case is the last position or a value that is absent).
Question 3
(a) Compute total = sum(scores) and mean = total / len(scores), then one pass counting the scores at or above the mean, returning round(mean, 1) and that count (4 marks: accumulate, average, compare, return). (b) total = 478, mean = 68.3 (68.29 rounded); the scores at or above 68.3 are 91, 76 and 83, so the function returns (68.3, 3). The 68 itself is below 68.29 and is not counted.
Question 4
(a) Convert to lower case first (text.lower()) and test each character against “aeiou” (4). (b) There are 2 uppercase letters (C and S). Input may be mixed case (“COMPUTER” versus “computer”), and testing only against the lower-case set misses A, E, I, O and U, undercounting the vowels – so normalise the case first (3).
Question 5
(a) Attributes: balance and owner; methods: deposit(amount), withdraw(amount), get_balance(). balance is private so it can only change through deposit and withdraw, and outside code cannot write a negative value or tamper with the balance (encapsulation, 6 marks). (b) 500 -> 750 after the deposit; the 900 withdrawal fails its 900 > 750 check and returns False with the balance unchanged at 750; then 180 comes out, leaving 570 (4).
Question 6
(a) Test if title in shelf first and remove only when present; if absent, return False or raise an exception instead of letting the program crash on a missing element (4). (b) shelf = [“A”, “C”] and count() returns 2 (3). (c) Private keeps the list changeable only through add and remove, so the class can check duplicates, keep an order or log every change; direct append or delete from outside bypasses those checks and leaves the state inconsistent (3).
How should the 75 minutes be split?
Direct answer: about 20 minutes on B1, 20 on B2 and 30 on B3, with 5 to check. Do the no-code B1 question first, because under time pressure it is the one most often answered as code.
Where these marks are usually lost
| Mistake | What it looks like | What it costs | Instead |
|---|---|---|---|
| Trace answer only | No per-iteration values | Process marks are most of the total | One line of total per iteration |
| Using a forbidden built-in | Calling sort() | Zero for that question | Write the sort or search yourself |
| OOP with attributes only | No methods, no reason for privacy | Loses every encapsulation mark | Attributes, methods, reason for private |
| Code where prose is asked | B1 wants written steps | Wrong question type | State input, steps, output in words first |
How to use this paper
First drill: the full 1 h 15 min, closed book, with no IDE autocomplete.
Mark it: trace answers step by step; for code, judge logic and edge cases, not style.
Second drill: redo three to seven days later inside an hour, and rewrite the code questions in the other language once.
What should I do after drilling this paper?
Direct answer: log questions where the trace or the edge cases failed; redo them in three to seven days, once in the other language; then move to Paper 1 (Theme A plus the case study) – there is no Paper 3 to drill, it was removed from the 2027 syllabus.
FAQ
Is this an IB past paper?
No. The questions, code and answers are TutorZone originals, not IB past papers, marking references or IB publications.
What is in IB Computer Science Paper 2?
2027 syllabus Theme B: B1 computational thinking, B2 programming, B3 OOP. SL 1 h 15 min, 50 marks, 35%; HL 2 hours, 80 marks, 40%, plus B4 abstract data types at HL.
Should I answer in Python or Java?
Either, depending on what your school teaches; the IB issues both versions of every programming question with the same mark scheme.
Official references
| Resource | What to check |
|---|---|
| IB Computer Science subject brief (first assessment 2027) | Confirm the Paper 1/2 times and weightings |
| IB Computer Science curriculum update (IBO) | Theme A/B scope and the removal of Paper 3 |
| https://www.tutorzone.com.hk/en-ib-computer-science-paper-1-mock-2027/ | IB Computer Science Paper 1 drilling mock |
Related: IB Computer Science drill guide (two-paper order, 75-minute pacing) · IB Computer Science Paper 1 drilling mock · practice area · IB Digital Society Paper 1 mock
Next step: find a tutor / register as a tutor
After drilling, the hard part is telling a conceptual error from a writing error. Tell us the year group, the school and your available times, and TutorZone will match you with a tutor who knows the HKEAA assessment requirements.
Demand for tutors in this subject is steady, and those who can explain the marking scheme and where marks are won are especially sought after. Register free; you pay only when a match succeeds.


