Skip to content

平成27年度 秋期 ITパスポート試験 問48

This question's explanation and your answers so far.

問48
頻出度★★☆

表に示す構成のデータを,流れ図の手順で処理する場合について考える。流れ図中のx,y,zをそれぞれデータ区分A,B,Cと適切に対応させれば,比較(“xか?”,“yか?”,“zか?”)の回数の合計は,最低何回で済むか。

データ区分件数
A10
B30
C50
その他10

流れ図:「開始」→「xか?」(No→「yか?」,Yes→「xの処理」);「yか?」(No→「zか?」,Yes→「yの処理」);「zか?」(No→「その他の処理」,Yes→「zの処理」);各処理後→「終わりか?」(No→「次のデータ」へ戻る,Yes→「終了」)。注記:流れ図中のx,y,zはデータ区分のA,B,Cのいずれかと対応させる。

出典 平成27年度 秋期 ITパスポート試験 問48
解説

問 48

  • ア

    正解 In the flowchart, each item of data is judged in the order «Is it x?» → (if No) «Is it y?» → (if No) «Is it z?», so the number of comparisons is 1 if it belongs to x, 2 if y, 3 if z, while the «Other» category that matches none of them runs all 3 comparisons. To minimize the total, categories with larger counts should be processed at an earlier stage (fewer comparisons). Since C=50 is the largest count, followed by B=30 and A=10, matching x=C, y=B, z=A is optimal. This gives C: 50×1=50, B: 30×2=60, A: 10×3=30, Other: 10×3=30, for a total of 50+60+30+30=170. Therefore the minimum number is 170, and the correct answer is ア.

  • Incorrectイ

    190 is the value obtained with a matching such as x=C, y=A, z=B (50×1+10×2+30×3+Other 10×3=190). Because the fairly large count B is assigned to z (3 comparisons), this is not the minimum. Since the question asks «at minimum how many times», it is not appropriate.

  • Incorrectウ

    230 is the value obtained with a matching such as x=B, y=A, z=C (30×1+10×2+50×3+Other 10×3=230). It places the largest count C at z (3 comparisons), so the number is far from minimal and is actually among the larger ones, hence inappropriate.

  • Incorrectエ

    250 is the value when x=A, y=B, z=C (10×1+30×2+50×3+Other 10×3=250), the worst matching in which categories with smaller counts are judged earlier. This is the maximum number, not the answer to this question, which asks for the minimum.

ここがポイント
  • In a flowchart that judges conditions one after another, the more upstream a condition is, the fewer comparisons it takes. To minimize the total number of comparisons, the standard approach is to «assign data categories with larger counts to earlier judgments (fewer comparisons)».
  • The weighted-sum idea: the number of comparisons for each category equals the number of judgments executed until it is reached (x=1, y=2, z=3, Other=3), multiplied by its count and then summed over all categories.
用語

Your answers