Skip to content

IB Computer Science Practice (Interactive)

Intuition

CS practice is like building with tools, each concept (variables, loops, functions) is a tool in your programming toolkit: Programming skills develop through practice, reading code, writing code, and debugging are all essential learning activities

Why it matters: Regular practice builds the problem-solving intuition needed for complex projects and exams

The key insight: Programming skills develop through practice, reading code, writing code, and debugging are all essential learning activities

IB — Computer Science Practice

10 auto-graded practice problems. Select an answer, submit, and review the explanation.


Worked Examples

Example 1: Boolean Logic

Problem: Simplify the Boolean expression: A⋅A‾+A⋅BA \cdot \overline{A} + A \cdot B

Solution: Step 1: A⋅A‾=0A \cdot \overline{A} = 0 (complement law: a variable ANDed with its complement is always false)

Step 2: 0+A⋅B=A⋅B0 + A \cdot B = A \cdot B (identity law: 0 OR anything is that thing)

Step 3: Answer: A⋅BA \cdot B

Key insight: Boolean algebra simplification follows the same rules as regular algebra, but with AND as multiplication and OR as addition. The key laws are: A⋅A‾=0A \cdot \overline{A} = 0, A+A‾=1A + \overline{A} = 1, A⋅1=AA \cdot 1 = A, A+0=AA + 0 = A.


Example 2: Big-O Analysis

Problem: Analyse the time complexity of this pseudocode:

for i = 1 to n:
    for j = 1 to n:
        print(i * j)

Solution: Step 1: Outer loop runs n times

Step 2: Inner loop runs n times for each iteration of outer loop

Step 3: Total operations = n×n=n2n \times n = n^2

Step 4: Time complexity: O(n2)O(n^2)

Key insight: For nested loops, multiply the number of iterations. If the inner loop depends on the outer loop variable (e.g., for j = 1 to i), the complexity is O(n2/2)=O(n2)O(n^2/2) = O(n^2).


Example 3: Binary Search Trace

Problem: Trace binary search for target 13 in array [2, 5, 8, 12, 16, 23, 38].

Solution: Step 1: low = 0, high = 6, mid = 3, array[3] = 12

Step 2: 12 < 13, so search right half: low = 4, high = 6

Step 3: mid = 5, array[5] = 23

Step 4: 23 > 13, so search left half: low = 4, high = 4

Step 5: mid = 4, array[4] = 16

Step 6: 16 > 13, so search left half: low = 4, high = 3

Step 7: low > high → target not found

Key insight: Binary search eliminates half the remaining elements at each step, which is why it’s O(log⁡n)O(\log n). But the array must be sorted first.


System Fundamentals


Computer Organization


Networks and Algorithms


Data Structures, Databases, and OOP

Common Mistakes

Confusing syntax errors with logic errors: Syntax errors prevent code from running (missing semicolons). Logic errors produce wrong output (incorrect algorithm). Don’t confuse debugging approaches.

Forgetting that arrays start at index 0: In most programming languages, the first element is at index 0, not 1. Off-by-one errors are extremely common.

Mixing up pass-by-value with pass-by-reference: Pass-by-value copies the value. Pass-by-reference shares the original. Modifying a parameter in a function affects the original only with pass-by-reference.

Cross-References