B4.1 Fundamentals of ADTs questions for IB Computer Science

201 questions on Fundamentals of ADTs, written by Augment in the style of IB exam papers. Six of them are below in full, to answer on paper.

  • IB Computer Science
  • Part of B4 Abstract data types
  • HL only

Questions by paper and level

PaperQuestions
Paper 2201

Counted on

Questions to try

Written by Augment in the style of IB exams, not past papers. Answer them on paper, then check each one against its markscheme with a free account.

Question 1 · CS-01061Paper 2 · 8 marks

A music streaming company is designing a new app. Before anyone writes code, the lead developer publishes a description of a Playlist abstract data type (ADT) with these operations:

Operation

Description

addTrack(t)

adds track t to the end of the playlist

removeTrack(t)

removes the first occurrence of track t

nextTrack()

returns the track after the one currently playing

isEmpty()

returns true if the playlist holds no tracks

  1. (a)

    Define the term abstract data type.

    2 marks

  2. (b)

    The description does not say whether the tracks are stored in an array or in a linked list.

    Outline why the description leaves this out.

    2 marks

  3. (c)

    Explain two benefits to the development team of agreeing the Playlist ADT before the code is written.

    4 marks

Question 2 · CS-01062Paper 2 · 7 marks

A heritage railway keeps the order of the carriages in a train as a singly linked list. Each node holds a carriage ID and a reference to the next node. Figure 1 shows the list for today's train.

Singly linked list. head points to node C14. Nodes in order: C14, C09, C22, C03, C17. Each node points to the next; the next pointer of C17 is null.
Figure 1

A diagonal line in a pointer field shows a null reference (None in Python, null in Java).

  1. (a)

    State the carriage ID held in the node referenced by head.

    1 mark

  2. (b)

    State the value of the next pointer in the node that holds C17.

    1 mark

  3. (c)

    Outline how the node holding C03 is found, starting from head.

    2 marks

  4. (d)

    A new carriage, C30, is attached to the front of the train.

    Sketch the linked list after C30 has been added, and state the order in which the two references must be changed.

    3 marks

Question 3 · CS-01063Paper 2 · 7 marks

A web browser stores the pages a user has visited in a tab as a doubly linked list. A reference current points to the node of the page on screen. The Back button moves current to the previous node and the Forward button moves it to the next node.

  1. (a)

    Outline why a doubly linked list is more suitable than a singly linked list for this feature.

    2 marks

  2. (b)

    The user presses Back twice, so current is now in the middle of the list, and then opens a new page from a link. The browser discards the pages that were ahead of current and adds the new page after it.

    Describe the changes made to the references when the new node is added.

    3 marks

  3. (c)

    Outline one disadvantage of using a doubly linked list rather than a singly linked list in this application.

    2 marks

Question 4 · CS-01064Paper 2 · 15 marks

A school library lets students reserve books that are on loan. The reserved titles are held in a singly linked list. The list class is shown below.

Python

Python
class ReservationList:
    def __init__(self):
        self.head = None

Java

Java
public class ReservationList {
    private Node head;

    public ReservationList() {
        head = null;
    }
}

Each node holds a book title (a string) and a reference to the next node.

  1. (a)

    Construct the class Node, including a constructor that takes a title.

    3 marks

  2. (b)

    Construct the method add_to_front (Python) / addToFront (Java) that adds a new title at the start of the list.

    3 marks

  3. (c)

    Construct the method display that outputs every title in the list, from the first to the last.

    3 marks

  4. (d)

    Construct the method contains that takes a title and returns true if that title is in the list and false otherwise. For example, if the list holds "Dune", "Emma" and "Holes", contains("Emma") returns true and contains("Matilda") returns false.

    4 marks

  5. (e)

    Explain why the library does not need to decide in advance how many reservations the list can hold.

    2 marks

Question 5 · CS-01065Paper 2 · 5 marks

A small text editor stores each line of a document as a string. The developer must choose between an array of lines and a singly linked list of lines. Users often insert and delete lines in the middle of long documents, and the editor's Go to line command jumps straight to a given line number.

Evaluate the use of a singly linked list rather than an array to store the lines of a document.

5 marks

Question 6 · CS-01066Paper 2 · 16 marks

A board-game app keeps the players in turn order in a circular singly linked list. The reference current points to the player whose turn it is. Figure 1 shows the list during a five-player game.

Circular singly linked list of players in order Ama, Bo, Cy, Dee, Eli. Each node points to the next; Eli's next pointer points back to Ama. The reference current points to Cy.
Figure 1

The classes used are:

Python

Python
class Node:
    def __init__(self, name):
        self.name = name
        self.next = None

class TurnRing:
    def __init__(self):
        self.current = None   # the player whose turn it is

Java

Java
public class Node {
    String name;
    Node next;

    public Node(String name) {
        this.name = name;
        this.next = null;
    }
}

public class TurnRing {
    private Node current;   // the player whose turn it is
}
  1. (a)

    Outline why a circular linked list is suitable for storing the turn order.

    2 marks

  2. (b)

    State the name of the player whose turn comes after Eli's.

    1 mark

  3. (c)

    Construct the method next_player (Python) / nextPlayer (Java) that passes the turn to the next player and returns that player's name. You may assume the ring is not empty.

    2 marks

  4. (d)

    Cy, the current player, is knocked out of the game and must be removed from the list.

    Explain why the program must visit the other nodes in the ring to remove the node referenced by current.

    3 marks

  5. (e)

    Construct the method remove_current (Python) / removeCurrent (Java) that removes the current player from the ring and passes the turn to the player after them. If the removed player was the only one left, current must become null (None).

    For example, in Figure 1, after the method runs the ring holds Ama, Bo, Dee and Eli and current points to Dee.

    6 marks

  6. (f)

    Suggest how storing the players in a circular doubly linked list would change the removal in part (e).

    2 marks

Practice all 201 in Augment

Free with an account. Every question has its markscheme, and Augment keeps the ones you got wrong so you can come back to them.

The notes on B4.1 Fundamentals of ADTs

Check your answers in Augment

A free account opens all 201 questions on Fundamentals of ADTs with their markschemes, and keeps a record of what you have marked.