IB Diploma Programme (DP) - SL & HL · Computer Science

Stacks and queues: Practice Questions

3 multiple-choice questions marked as you go, and 3 written questions with worked solutions. All on Stacks and queues.

6 questions19 marksFree, no account
Question 1
1 mark

A Binary Search Tree (BST) is built by inserting values in the following order: 50, 30, 70, 20, 40, 60, 80. If the root node (50) is deleted and replaced by its in-order successor, which value will be the new root of the tree?

Question 2
1 mark

In the context of Abstract Data Structures, what is the primary role of a hash function when implemented in a hash table?

Question 3
1 mark

Consider a Circular Linked List where a single pointer, last, points to the final node in the list. What is the Big O time complexity for inserting a new node at the beginning (head) of the list?

Question 4
3 marks

Outline how a stack data structure is used by the system to manage sub-program calls and handle returns during program execution.

Write your answer out first, then check it against the worked solution.

Question 5
5 marks

A singly linked list stores nodes where each node contains data and a pointer to the next node. A developer uses an external pointer, start, pointing to the first node.
Describe the algorithm steps required to delete a node that contains a specific target value from the middle of the linked list without causing memory disconnection.

Write your answer out first, then check it against the worked solution.

Question 6
8 marks

A customer service system manages incoming support tickets using abstract data structures. Each ticket has a unique integer ID, and the system dynamically processes them using a single linked list and a binary search tree (BST).

(a) State one advantage and one disadvantage of using a dynamic data structure, such as a linked list, compared to a static data structure like an array for storing support tickets. [2]

(b) The following sequence of ticket IDs arrives and is inserted in this order into an initially empty Binary Search Tree (BST):
\(45, 23, 67, 12, 34, 56, 89, 78\)

(i) State the values visited during a pre-order traversal of the resulting tree. [2]
(ii) State the values visited during an in-order traversal of the resulting tree. [1]

(c) The linked list implementation uses nodes, where each node contains data and a reference next. The pointer head points to the first node in the list. The recursive sub-program countPriority(Node current, int threshold) counts the number of tickets whose ID is greater than threshold.

Construct the recursive algorithm in pseudocode for countPriority(Node current, int threshold). [3]

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, graded as you go.

Practice More