Practice IB Computer Science (CS) Topic 4. Computational Thinking, Problem-solving and Programming with authentic exam-style questions for both SL and HL students. This question bank focuses on the exact syllabus content for 4. Computational Thinking, Problem-solving and Programming and mirrors Paper 1, 2, 3 style where relevant.
Get instant solutions, detailed explanations, and build confidence with questions aligned to IB examiner expectations.
A company has 600 employees whose names are currently stored using an array called NAMES. The names are stored as surname, first name. For example: Smith, Jane, Uysal, Rafael, Ahmed, Ishmael, Jonsonn, Sara, ...
The names in the array are kept in a random order. However, it would be more useful if they were kept in alphabetical order.
The company's staff list is now organized in arrays in alphabetical order.
A binary search was used to find a specific name in the surname array.
Describe the process a binary search would follow to find a record in the surname array.
Outline one benefit of using sub-programmes to implement your algorithms from the sorting and searching parts of this question.
Construct a pseudocode algorithm that will store the surnames in one array and first names in another.
Construct a pseudocode algorithm that will sort the surnames into alphabetical order using the bubble sort method. The order of the first names must also be changed so that they keep the same index as their corresponding surname.
A delivery company uses trains in its operations. It uses an object-oriented program to keep track of its trains and the parcels that it carries. The company has many objects in their program; here are some of them.
| Object | Description |
|---|---|
| Train | Each Train is made up of RollingStock objects, each of which is either a Wagon or an Engine. |
| RollingStock | A RollingStock object can be an Engine (that can pull) or a Wagon (that needs to be pulled). Each RollingStock has a unique ID number and a weight. |
| Engine | A variety of RollingStock. Each Engine has a maximum weight that it can pull. |
| Wagon | A variety of RollingStock. Each Wagon has a maximum cargo weight. |
| Parcel | Each Parcel is tagged with a tracking number, the addresses from where it came (origin) and to where it is going (destination) and its weight. |
The following code implements the Train class used in this program.
public class Train { // Wagons currently coupled to the train private Wagon[] mWagons; private int mWagonCount;
public Train(int maxWagons) { mWagons = new Wagon[maxWagons]; mWagonCount = 0; }
public void addWagon(Wagon w) { if (mWagonCount < mWagons.length) { mWagons[mWagonCount] = w; mWagonCount++; } }
public int getNumberOfWagons() { return mWagonCount; }
public Wagon removeWagon() { if (mWagonCount > 0) { mWagonCount--; Wagon removed = mWagons[mWagonCount]; mWagons[mWagonCount] = null; return removed; } return null; }}Define the function of a constructor.
Outline the advantages of polymorphism, using the RollingStock class as an example.
Construct a unified modelling language (UML) diagram of the Train class.
Construct a method getNumberOfWagons(), part of the Train class, that returns the number of wagons currently coupled to the train.
Construct the removeWagon() method that will remove one wagon from a train and return the removed object. Include appropriate error checking.
A company is using a prototyping approach as part of their software development process.
Outline one advantage of prototyping.
Outline one situation in which the use of a prototype is not the best approach.
A school has 100 students. All student names (strings) and student ID numbers (five-digit integers) are held in two separate one-dimensional arrays named SID and SNAMES.
| SID | [0] | SNAMES | |
|---|---|---|---|
| [0] | 10011 | Aron Zucker | |
| [1] | 10002 | [1] | Cary Armand |
| [2] | 11876 | [2] | Pia Baranger |
| [3] | 10122 | [3] | Peter Bow |
| [4] | 22103 | [4] | John Buffet |
| ... | ... | ... | ... |
| [99] | 32000 | [99] | Evan Apples |
For example, student Pia Baranger has ID number 11876.
A binary search algorithm is not used to find a particular name in array SNAMES.
Three collections store the student ID numbers of students who have chosen each sport:
Each Collection supports the methods resetNext(), hasNext() and getNext().
State the reason for not using a binary search.
Construct an algorithm in pseudocode for the method isIn(x, COL).
Construct an algorithm in pseudocode that will output the number of students who have chosen both tennis and football. The method isIn() should be used in your answer.
Construct an algorithm in pseudocode that will output the names of students who have not yet chosen any one of the three sports. An appropriate message should be displayed if every student has chosen a sport.
IB Computer Science SL Paper 1
Construct a logic diagram for the following expression. NOT A OR (A AND B)