IB Recipe Book

This page contains the IB way to code common operations found in Paper 1 (Pre 2026)

Array vs Python List

1. Data Type Flexibility

  • Array: Typically, arrays are homogeneous, meaning all elements must be of the same data type (e.g., all integers or all floats).

  • Python List: Lists in Python are heterogeneous, allowing you to store elements of different types (e.g., integers, strings, objects) in the same list.

2. Size and Resizing

  • Array: The size of an array is fixed upon creation. You cannot change its size without creating a new array.

  • Python List: Lists are dynamic; you can easily add or remove elements, and the list will resize automatically.

3. Memory Management

  • Array: Arrays are more memory-efficient for large datasets since they store elements in contiguous memory locations.

  • Python List: Lists may use more memory due to their flexibility and the overhead of storing type information for each element.

4. Performance

  • Array: Generally, arrays can offer better performance for numerical computations due to their fixed size and type.

  • Python List: While lists are versatile, they may be slower for certain operations compared to arrays, especially when dealing with large datasets.

5. Built-in Functions

  • Array: In languages like C, you have to implement many operations manually (like sorting or searching).

  • Python List: Python provides a rich set of built-in methods for lists (like .append(), .remove(), and .sort()) that make manipulation straightforward.

Things to avoid

  1. Do not use map(); filter(); enumerate(); max(); min(); set(); reversed()

  2. Use of set, tuple, or dictionary data types

Creating an Array during IB Exam

This code mimics the creation fixed size arrays.

Explanation

  • Variable size is inputted to limit the size of the array

  • Variable array is initialized using list comprehension to create a list in python with size many empty spaces for future inputted value

    • Empty spaces are using the None keyword for empty values

  • the for loop iterates size many times to input values at index i

    • If inputting numeric values please type cast the input() function in the for loop

Find the maximum/minimum value in an array

This is assuming we can't use max() nor min()

Find the maximum/minimum value's index in an array

This is where we find the index value of our max and min values

Calculate the average from an array of values

Linear search an array to find a target value

Binary search an array to find a target value

How to sort an array of data using Bubble Sort

How to sort connected arrays using bubble sort

Determine the difference between one array and another

We are trying to output a new array/collection that determines which values in one of the array does not appear in the other

Access individual digits from a number from right to left without String manipulation

Last updated