IPA FE Subject B sample Question 14

A question IPA Japan published in 基本情報技術者試験 科目B サンプル問題 問14, translated into English. ITPEC is based on the same exams.

From the answer group below, select the correct answer to be inserted into blank in the description. Here, the array index starts at 1.

This is a program that, based on an array that has one or more elements and is sorted in ascending order, returns five values that characterize the array.
When the function summarize is called as summarize({0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}), the return value is blank.

[Program]
○ real: findRank(real []: sortedData, real: p)
integer: i
i ← (p × (the number of elements in sortedData - 1)) rounded up to the nearest whole number
return sortedData[i + 1]
○ real []: summarize(real []: sortedData)
real []: rankData ← {} /* array with 0 elements */
real []: p ← {0, 0.25, 0.5, 0.75, 1}
integer: i
for (increase i from 1 to the number of elements in p by 1)
add the return value of findRank(sortedData, p[i]) to the end of rankData
endfor
return rankData

Answer group

Explanation

{0.1, 0.4, 0.6, 0.8, 1} — findRank rounds p × 9 up to a whole number i and returns the element at position i + 1.

sortedData has 10 elements, so each call computes p × (10 − 1) = p × 9, rounds it up, and adds 1 for the index:

p[i]p × 9ipositionvalue
00010.1
0.252.25340.4
0.54.5560.6
0.756.75780.8
199101

summarize adds each value to the end of rankData in this order.

All options agree on the first and last values; each wrong one has a middle value that comes from rounding down instead of up.

Answer (h)

Why not others:

  • •(a), (b), (c) and (d) — 0.3 second is position 3, i = 2: 2.25 rounded down (option (a) rounds all three down)
  • •(e) and (f) — 0.5 in the middle is position 5, i = 4: 4.5 rounded down
  • •(g) — 0.7 fourth is position 7, i = 6: 6.75 rounded down

Key rule: Trace a rank formula one value at a time, applying the rounding the program states (up here) before adding the + 1 for indexes that start at 1.

Math & Data Science · 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.