ITPEC FE Subject B October 2024 Question 14
From the answer group below, select the correct answer to be inserted into blank in the description. Here, the array indexes start at 1.
The function summarize receives the array sortedData sorted in ascending order and returns five values that characterize the array. The array sortedData must have at least one element. The summarize calls the findRank with two arguments, sortedData and q.
When the function summarize is called as summarize(, the return value is blank.
Answer group
Explanation
{0.1, 0.3, 0.5, 0.7, 1} — findRank returns the element at position floor(q × (n − 1)) + 1, giving the minimum, the quartiles, the median and the maximum.
sortedData has 10 elements, so n - 1 = 9. Each call computes j as the floor of q × 9 and returns sortedData[:
Each value is added to the end of rankData in that order.
Answer (e)
Why not others:
- •(a) — the first five elements: that is
jfrom q × 4, using the 5 elements ofqinstead of the 10 ofsortedData - •(c) — reads
sortedData[j]without the + 1, which gives 0.2, 0.4, 0.6 and 0.9 for the last four (and position 0, outside the array, for q = 0) - •(f) — differs only at q = 0.75: 0.8 is position 8, which needs j = 7, rounding 6.75 up instead of taking the floor
- •(b) and (d) — the last value is not 1, yet q = 1 gives j = 9, position 10, the maximum
- •(g) and (h) — the middle value is 0.6 or 0.7, yet the floor of 4.5 is 4, position 5, value 0.5
Key rule: A formula that yields an offset from 0 needs + 1 when indexes start at 1; trace the extremes (q = 0 and q = 1) first to catch off-by-one errors.
Math & Data Science · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.