IB COMPUTER SCIENCE | B2 ASSESSMENT

PROGRAMMING: END OF TOPIC REVIEW

Assess programming fundamentals, data structures, constructs, algorithms and file processing through scored retrieval, applied traces and developed written responses.

BEFORE YOU BEGIN

This substantial review covers all 18 B2 objectives. Use several sessions if needed: quick checks, applied traces, then written construction and explanations. Only B2.4.4 and B2.4.5 recursion are HL-only; other objectives are common SL/HL.

Sections A and B award one point for each fully correct automatic item, with no partial credit within an item. Section C has separately suggested content marks. These are original practice questions, not an official IB paper, grade boundary or prediction.

Choose your level below. Write calculations, diagrams and Section C answers in your exercise book before revealing guidance. Answers and selections last while the page remains open.

Automatic total: 48 points. Suggested written total: 108 marks, assessed separately.

A | QUICK CHECKS

Answer without notes. A1–A22 and B1–B22 are common SL/HL; A23–A24 and B23–B24 are HL-only. Section C has 16 common tasks and two HL tasks. Select every correct answer in checkbox items.

A1 | Which choices match the intended Python data?

Select all correct answers. One point requires the complete correct set.

A2 | Which statements about function scope are correct?

Select all correct answers. One point requires the complete correct set.

A3 | Which Python string statements are correct?

Select all correct answers. One point requires the complete correct set.

A4 | Which describe exception control flow?

Select all correct answers. One point requires the complete correct set.

A5 | Which are useful debugging practices?

Select all correct answers. One point requires the complete correct set.

A6 | Which distinguish logical size and storage capacity?

Select all correct answers. One point requires the complete correct set.

A7 | Which are correct for arrays and lists?

Select all correct answers. One point requires the complete correct set.

A8 | Which match stack operations?

Select all correct answers. One point requires the complete correct set.

A9 | Which match a FIFO queue?

Select all correct answers. One point requires the complete correct set.

A10 | Which support correct instruction sequence?

Select all correct answers. One point requires the complete correct set.

A11 | Which describe a Python if/elif/else chain?

Select all correct answers. One point requires the complete correct set.

A12 | Which implement inclusive age 12–17 eligibility correctly?

Select all correct answers. One point requires the complete correct set.

A13 | Which statements about loops are correct?

Select all correct answers. One point requires the complete correct set.

A14 | Which distinguish return from print?

Select all correct answers. One point requires the complete correct set.

A15 | Which support modular programs?

Select all correct answers. One point requires the complete correct set.

A16 | Which standard Big O classifications are linear?

Select all correct answers. One point requires the complete correct set.

A17 | Which are prerequisites or guarantees of the shown search styles?

Select all correct answers. One point requires the complete correct set.

A18 | Which describe the standard sorts used here?

Select all correct answers. One point requires the complete correct set.

A19 | Which statements about auxiliary space are correct?

Select all correct answers. One point requires the complete correct set.

A20 | Which statements about Python file modes are correct?

Select all correct answers. One point requires the complete correct set.

A21 | Which distinguish Python readline results?

Select all correct answers. One point requires the complete correct set.

A22 | Which support correct file processing?

Select all correct answers. One point requires the complete correct set.

A23 | HL ONLY: Which explain recursive execution?

Select all correct answers. One point requires the complete correct set.

A24 | HL ONLY: Which describe non-branching recursion?

Select all correct answers. One point requires the complete correct set.

B | APPLY YOUR KNOWLEDGE

Each question is a fresh run with its own stated data. Do not carry changed state from another question. Trace or calculate in your book before entering the final answer. Programs P1–P4 are common SL/HL; P5 is used only by a labelled HL item.

PROGRAM P1
def change(number, values):
    number = number + 2
    values.append(number)
    return number

number = 10
values = [8]
result = change(number, values)
PROGRAM P2
total = 0
for number in range(1, 4):
    total = total + number
print(total)
PROGRAM P3
def binary_search(values, target):
    low = 0
    high = len(values) - 1
    while low <= high:
        middle = (low + high) // 2
        if values[middle] == target:
            return middle
        elif values[middle] < target:
            low = middle + 1
        else:
            high = middle - 1
    return -1
PROGRAM P4
def bubble_sort(values):
    comparisons = 0
    for end in range(len(values) - 1, 0, -1):
        swapped = False
        for index in range(end):
            comparisons = comparisons + 1
            if values[index] > values[index + 1]:
                values[index], values[index + 1] = values[index + 1], values[index]
                swapped = True
        if not swapped:
            break
    return comparisons
PROGRAM P5 | HL ONLY
def count_up(n):
    if n == 0:
        return
    count_up(n - 1)
    print(n)
B1 | P1: what is the caller’s number after change returns?
B2 | text = "COMPUTER". What is text[1:4]?
B3 | int("zero") is inside a try with except ValueError printing Invalid and finally printing Done. Which output occurs?
B4 | A debugger pauses before total = total + value. total is 8 and value is 5. What is total immediately after that assignment executes?
B5 | A toy dynamic array has size 4, capacity 4 and doubles capacity when a fifth item is appended. What is its new capacity?
B6 | grid = [[4,7,2],[5,1,6]]. What is grid[1][2]?
B7 | An empty stack receives push A, push B, pop, push C. What is returned by the next pop?
B8 | A circular queue has capacity 5 and rear = 4 as its next write position. After a valid enqueue, what is rear?
B9 | Quantity is 3 and unit price 4. subtotal = quantity * price, then total = subtotal - 2. What is total?
B10 | Fictional categories: if mark >= 80 output High; elif mark >= 50 output Pass; else output Develop. For mark = 85, what is output?
B11 | P2: what value is printed?
B12 | A Python function only executes print(12) and reaches its end. What does result = that_function() assign to result?
B13 | A constant-work inner body runs n times for each of n outer iterations. Under the n² model, by what factor does its work grow when n doubles?
B14 | P3: search [3,7,11,15,19,23,27,31] for 27. What index is returned?
B15 | P3: search the same eight values for absent target 20. How many midpoint probes occur before -1 is returned?
B16 | A left-to-right first-match linear search inspects [7,4,7,9] for 7. Which result is correct?
B17 | P4: what is the list after the first complete pass on [5,1,4,2,3]?
B18 | P4: how many data comparisons are returned for the complete sort of [5,1,4,2,3]?
B19 | Standard selection sort scans each suffix and avoids self-swaps. How many data comparisons does it make for 5 already sorted items?
B20 | A file contains "Old\n". Open it successfully with w and write "New\n". Which contents remain after close?
B21 | A Python text file contains the characters "8\n\n5". Calling readline repeatedly through EOF yields which sequence?
B22 | A streaming score total skips blank or invalid integer lines. File lines are 8, blank, bad, 5. What is the final total?
B23 | HL ONLY: factorial(n) calls factorial(n-1) until n == 0. How many factorial invocations are entered for factorial(4), including the base call?
B24 | HL ONLY: P5 is called with 3. What is the printed order?

CHECK SECTIONS A AND B

Unanswered items receive zero. Each checkbox item requires all correct choices and no incorrect extras. Written marks are separate. Changing an answer or level requires resubmission.

C | WRITTEN COMMUNICATION AND SUBJECT KNOWLEDGE

Write in your exercise book before revealing the guidance. The table gives practical guidance based on the IB command terms supplied in the guide; it is not the Cambridge command-word table.

In particular, IB compare focuses on similarities, while distinguish asks for differences. If you need to address both, the question can request each separately. All main commands below are highlighted.

IB command term What to provide here Practical approach
Construct Information in diagrammatic or logical form Supply complete code/algorithm, including initialization, stopping and failure paths.
Trace Follow and record actions of an algorithm Separate arguments, variables, decisions, outputs and returned results.
Calculate A numerical result with relevant working Show counts or formula stages before the answer.
Describe A detailed account Give relevant features and an ordered process where useful.
Explain A detailed account including reasons or causes Link correct ideas using because, therefore, resulting in or leading to.
Compare and contrast Similarities and differences, referring to both throughout Use both for shared properties and whereas for differences.
Distinguish Clear differences State how roles or behaviours differ.
Evaluate An appraisal weighing strengths and limitations Connect trade-offs to the scenario and support the conclusion.

A connective earns no automatic mark by itself: it must express an accurate relationship. For example, “resetting total inside the loop discards earlier contributions, therefore the final value includes only the last item” explains a mechanism and consequence. Suggested marks reward subject content, not extra unofficial grammar marks.

C1 | LOCAL STATE AND A SHARED LIST

6 suggested marks | COMMON SL/HL

Use P1. Trace the local parameter, caller variable, returned result and list contents. Then explain why the list and the caller’s number behave differently.

C2 | CONSTRUCT A STRUCTURED SUBSTRING

6 suggested marks | COMMON SL/HL

A code has the format ABC-2027-0042. Assume its format is already validated. Construct a Python function returning the four-character year and final four-character identifier as two strings. Explain the slice bounds and why the identifier should stay text.

C3 | CONVERSION AND EXCEPTION FLOW

6 suggested marks | COMMON SL/HL

Construct a Python function accepting raw numeric text and returning 12 divided by its integer value. Return distinct messages for invalid integer text and zero. Explain why one conversion check does not cover both failures.

C4 | DEBUG A LOST RUNNING TOTAL

6 suggested marks | COMMON SL/HL

A loop over [4,7,2] executes total = 0 inside the body immediately before total = total + value. Explain the logic error and a systematic debugging approach, then state the repair and expected total.

C5 | SIZE, CAPACITY AND GROWTH

6 suggested marks | COMMON SL/HL

A toy resizable array starts with capacity 2 and size 0, doubling capacity only when an append finds it full. Trace five appends. Evaluate the benefits and costs of this growth strategy compared with a fixed-capacity structure.

C6 | CONSTRUCT ROW AND GRAND TOTALS

6 suggested marks | COMMON SL/HL

Construct Python code reporting each row total and one grand total for grid = [[4,7,2],[5,1,6]]. Explain where both accumulators are initialized.

C7 | STACK FOR UNDO HISTORY

6 suggested marks | COMMON SL/HL

A text editor stores previous text states in a stack before each edit. Trace an initial empty string followed by edits to A and AB, then two undo actions. Explain why a stack suits the requirement and how empty-history handling should work.

C8 | CIRCULAR QUEUE WRAPAROUND

6 suggested marks | COMMON SL/HL

A circular queue of capacity 5 uses front as next read, rear as next write and count as occupancy. Start empty with both indexes 0. Enqueue A,B,C,D; dequeue twice; enqueue E,F,G. Trace the physical slots, logical order and final indexes. Explain how count distinguishes full from empty.

C9 | ORDER DEPENDENT CALCULATIONS

6 suggested marks | COMMON SL/HL

A ticket program receives quantity as text. Unit price is 4.50 and a 10% discount applies to the subtotal. Construct the correctly ordered calculation and explain why conversion and intermediate dependencies matter. Assume a valid positive integer quantity.

C10 | CONSTRUCT EXCLUSIVE CATEGORIES

6 suggested marks | COMMON SL/HL

Fictional categories are High for 80–100, Pass for 50–79 and Develop for 0–49. Construct Python selection for an already converted integer mark, rejecting values outside 0–100. Explain why branch order and a chain matter.

C11 | LOOP UNTIL A SENTINEL

6 suggested marks | COMMON SL/HL

Construct a program that reads integer values as text until the exact word stop, then reports the total and count of the numeric values. Assume each non-sentinel value is a valid integer. Explain how the sentinel is excluded and the loop progresses.

C12 | MODULAR TEMPERATURE REPORT

6 suggested marks | COMMON SL/HL

Construct functions separating average calculation from message formatting for a nonempty list of numeric temperatures. A coordinating function must return a report string. Explain how this separation supports testing and reuse.

C13 | CALCULATE AND EVALUATE GROWTH

6 suggested marks | COMMON SL/HL

Algorithm X makes two sequential full scans of n items. Algorithm Y performs constant work for every ordered pair of those items. Calculate their standard time bounds, then evaluate scalability if both satisfy the same required output.

C14 | CONSTRUCT AND TRACE BINARY SEARCH

6 suggested marks | COMMON SL/HL

Construct an ascending binary search returning an index or -1. Then trace target 20 in [3,7,11,15,19,23,27,31] and explain its sorted-data requirement.

C15 | COMPARE SORTS AND EVALUATE THE COSTS

6 suggested marks | COMMON SL/HL

Compare and contrast optimized bubble sort and standard swap-based selection sort. Evaluate their suitability for a small list where exchanges are expensive and memory is limited. Include time, auxiliary space and stability.

C16 | CONSTRUCT FILE PROCESSING WITH CLEANUP

6 suggested marks | COMMON SL/HL

scores.txt stores one integer per line. Construct a Python program that skips invalid/blank lines and writes valid count and total to a different file summary.txt. Close resources safely. Explain why input must be read before output replacement and why raw blank lines are not EOF.

C17 | HL | RECURSION MECHANISM AND LIMITS

6 suggested marks | HL ONLY

Explain the call stack and unwinding for factorial(3) using base factorial(0)=1. Then evaluate recursion for this task under a unit-cost arithmetic model.

C18 | HL | CONSTRUCT AND TRACE A SINGLE CHAIN

6 suggested marks | HL ONLY

Construct a non-branching recursive function returning the sum of even terms from 2 to n, for a non-negative even integer n. Trace n=6 and explain why the reduction terminates for the stated domain.

CHECK THE QUALITY OF YOUR WRITING

Did you answer the command? For explain, check the reason or cause; for compare, address both items through similarities; for compare and contrast, include differences too; for discuss, balance relevant factors in context; for distinguish, make the differences explicit; for evaluate, weigh strengths and limitations and support your conclusion.

For construct, check labels, connections and completeness. For calculate, show enough working to follow your method and label units. Select two weak responses and rewrite them after revising. Keep the written total separate from your automatic result.

YOUR NEXT REVISION STEP

Submit the automatic sections for targeted revision links.

Record your own written marks using the suggested points. Choose two weaknesses and attempt new examples after revising. Use the B2 revision page for worked content and a personal flashcard list, or return to the IB course index.