IPA FE Subject B 2026 Question 4
A question IPA Japan published in 令和8年度 基本情報技術者試験 科目B 公開問題 問4, translated into English. ITPEC is based on the same exams.
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array index starts at 1.
A singly linked list is represented by two arrays, the array dataList and the array pointerList. dataList stores the values of the elements of the list, and pointerList stores the index of the element of dataList that corresponds to the next element of the list. The head of the singly linked list is the pair of dataList[1] and pointerList[1]. The element of pointerList that corresponds to the tail of the singly linked list is undefined. The elements of dataList that do not store values of elements of the singly linked list, and the corresponding elements of pointerList, are undefined.
The contents of dataList and pointerList handled by the program are shown in Figure 1. The index of the element next to the head is 3, stored in pointerList[1], and its value is 20, stored in dataList[3]. The index of the element after that is 2, stored in pointerList[3], and its value is 30, stored in dataList[2].
Figure 1 Contents of dataList and pointerList
The function orderList returns an array that stores the values of the singly linked list represented by dataList and pointerList in Figure 1, in order, following the singly linked list from its head. The array returned by the function orderList is shown in Figure 2.
Figure 2 Array returned by the function orderList
Answer group
Explanation
A: pointerList[p], B: pointerList[p] — after storing the current value, stop if the element has no successor, otherwise follow its pointer.
p is the index of the current element, starting at the head, 1. Each pass adds dataList[p] to linearList. The tail is the element whose pointerList entry is undefined, so A is pointerList[p]: when it is undefined, the value just added was the last one and the loop ends. Otherwise the next element is at index pointerList[p], so B is pointerList[p].
Trace with Figure 1:
- •
p= 1: add 10;pointerList[1]= 3, sopbecomes 3 - •
p= 3: add 20;pbecomes 2 - •
p= 2: add 30;pbecomes 4 - •
p= 4: add 40;pointerList[4]is undefined, so the loop ends
The result is {10, 20, 30, 40}, as in Figure 2.
Answer (d)
Why not others:
- •(a) and (c) — set
p ← i, which walks the array in storage order instead of following the links: both return {10, 10, 30, 20, 40} - •(b) — tests
dataList[p], which is defined for every element of the list, so the loop does not stop after 40:pbecomes undefined and the fifth pass readsdataListat an undefined index
Key rule: When walking a linked list, test the link for the end and advance by the link, never by a counter or by the data.
Linked List · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.