Practice D.4 Advanced program development with authentic IB Computer Science (CS) exam questions for both SL and HL students. This question bank mirrors Paper 1, 2, 3 structure, covering key topics like programming concepts, algorithms, and data structures. Get instant solutions, detailed explanations, and build exam confidence with questions in the style of IB examiners.
Full details of the customers are stored as objects of the Customer class. This class is partially shown below:
public class Customer
{
private String memberId;
private String email; //email address (assume only 1 per customer)
public Customer(String a, String b)
{
memberId = a;
email = b;
}
public String getMemberId()
{
return memberId;
}
public String getEmail()
{
return email;
}
}
The objects can be accessed through the linked list allCustomerswhich is declared in the main (driver) class as follows:
LinkedList<Customer> allCustomers = new LinkedList<Customer>()
Outline why a linked list structure has been chosen for allCustomers.
Construct the method goldMails()that will return an ArrayListcontaining the email addresses of all current “Gold” members. You should make use of any previously defined methods.
An image processing software needs to perform operations on a collection of pixels.
Explain the advantages of using library collections like ArrayList or LinkedList in this context.
Construct code to add a pixel to an ArrayList and iterate over all pixels to apply a filter.
Describe one situation where a LinkedList might be preferred over an ArrayList in this application.
A text editor needs to implement an undo functionality using stacks.
Describe how a stack can be used to implement the undo feature.
Construct code to push actions onto the stack when changes are made.
Construct code to pop actions from the stack to undo the last change.
A network routing system uses a binary tree to store and retrieve routing information.
Outline the features of the abstract data type (ADT) binary tree.
Explain the importance of style and naming conventions in the code for the binary tree implementation.
Describe one application of binary trees in computing, with reference to the routing system.
A compiler uses a stack to evaluate expressions in reverse Polish notation.
Outline the features of the abstract data type (ADT) stack.
Explain why a stack is suitable for expression evaluation.
Construct methods push and pop for a static implementation of a stack to handle integer operands.
A gaming application uses recursion to generate a maze.
Describe an application of recursive algorithms in maze generation.
Construct a recursive method generateMaze that divides a grid into subgrids.
Explain why recursive algorithms are rarely used in practice despite being elegant.
A palindrome is a word that spells the same backwards. For example, the words “kayak” and “rotor” are palindromes.
A word can be checked to see if it is a palindrome by comparing the first letter with the last letter and then the second letter with the next-to-last letter and so on.
Explain why recursion is a suitable tool to use when performing this check.
The method palindrome()is called by**boolean** t = palindrome(word);
where wordis a String variable.
Without writing code, describe the recursive method palindrome()that returns whether or not a word is a palindrome.
A file system uses a recursive algorithm to display all files and directories.
Define the term object reference in the context of linked data structures.
Construct a class FileNode that represents a file or directory, including a reference to the next FileNode.
Construct a recursive method listFiles that prints the names of all files and directories starting from a given FileNode.
A mathematical software needs to compute the factorial of large numbers using recursion.
Describe how recursion can be applied to calculate the factorial of a number.
Construct a recursive method factorial that computes the factorial of an integer n.
Trace the recursive calls of factorial(4) and show all steps clearly.
Outline the need for higher level languages.
Explain two benefits of using sub-procedures within a computer program.
Identify three characteristics of a collection.
Construct in pseudocode an algorithm, using the access methods of a collection, which will iterate through the collection NUMBERS and count how many elements stored in the collection are in the interval [-1,1]. The final answer should be output.