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].

Index12345dataList10302040Index12345pointerList342
Note:Shading indicates that the element is undefined.

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.

Index123410203040

Figure 2 Array returned by the function orderList

[Program]
global: integer []: dataList ← {10, 30, 20, 40, undefined}
global: integer []: pointerList ← {3, 4, 2, undefined, undefined}
○ integer []: orderList()
integer: i, p ← 1
integer []: linearList ← {} // array with 0 elements
for (increase i from 1 to the number of elements in dataList by 1)
add the value of dataList[p] to the end of linearList
if (A is undefined)
exit the for block
endif
p ← B
endfor
return linearList

Answer group

OptionAB

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, so p becomes 3
  • •p = 3: add 20; p becomes 2
  • •p = 2: add 30; p becomes 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: p becomes undefined and the fifth pass reads dataList at 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.