テクノロジ系 2025年度 問98 ★★★★☆ Hard
4個の要素から成るデータの並びを,次の手順を繰り返して昇順に整列するとき,整列が終了するまでに(1)から(3)の一連の手順は,何回実行されるか。ここで,最初はデータの並び全体を整列対象とする。
データの並び:[27, 42, 33, 12]
[手順]
(1) 整列対象中の要素の最大の値を選び,最後の要素と入れ替える。
(2) 最後の要素を整列対象から外す。
(3) 整列対象に要素が1個以上残っていれば,(1)から(3)の一連の手順を実行する。残っていなければ,整列完了なので終了する。
English
When sorting 4 elements in ascending order by repeating the procedure below, how many times is the series of steps (1)-(3) executed until sorting is complete?
Data: [27, 42, 33, 12]
(1) Find the maximum in the sort target and swap it with the last element.
(2) Remove the last element from the sort target.
(3) If one or more elements remain, execute (1)-(3) again; otherwise, sorting is complete.
မြန်မာ
အောက်ပါ လုပ်ငန်းစဉ်ကို ထပ်ခါတလဲလဲ ဆောင်ရွက်ကာ ဒြပ်စင် ၄ ခု ပါဝင်သော ဒေတာကို ascending order ဖြင့် စီစဉ်ရာ sorting ပြီးစီးသည်အထိ (1)-(3) လုပ်ဆောင်ချက်များ မည်မျှ ကြိမ် ဆောင်ရွက်ရမည်နည်း?
ဒေတာ: [27, 42, 33, 12]
(1) sort target တွင် အကြီးဆုံးတန်ဖိုးကို ရှာဖွေ၍ နောက်ဆုံးဒြပ်စင်နှင့် လဲလှယ်သည်။
(2) နောက်ဆုံးဒြပ်စင်ကို sort target မှ ဖယ်ရှားသည်။
(3) sort target တွင် ဒြပ်စင် တစ်ခုနှင့်အထက် ကျန်ရှိပါက (1)-(3) ကို ထပ်ဆောင်ရွက်သည်; မကျန်ပါက sorting ပြီးစီးသည်။
Correct answer: ウ — 4
選択ソート(降順で最大値を末尾に移動)の動作をトレースする。
初期:[27, 42, 33, 12](4要素)
1回目:最大42と末尾12を交換→[27, 12, 33, 42],42を除外(残3要素)
2回目:最大33は末尾のまま→[27, 12, 33],33を除外(残2要素)
3回目:最大27と末尾12を交換→[12, 27],27を除外(残1要素)
4回目:最大12は末尾のまま,12を除外(残0要素)→終了
合計4回実行(ウ)。
English
Tracing the selection sort procedure:
Initial: [27, 42, 33, 12] (4 elements in scope)
Cycle 1: max=42, swap with 12 → [27, 12, 33, 42]; remove 42 (3 remain)
Cycle 2: max=33, already last → [27, 12, 33]; remove 33 (2 remain)
Cycle 3: max=27, swap with 12 → [12, 27]; remove 27 (1 remains)
Cycle 4: max=12, already last → [12]; remove 12 (0 remain) → terminate
Total: 4 executions → option ウ.
မြန်မာ
ရွေးချယ်စီစစ်ခြင်းလုပ်ငန်းစဉ်ကို ခြေရာခံခြင်း - စတင်ချက်: [27, 42, 33, 12] (အဓိပ္ပာယ်ဆောင်ပစ္စည်း ၄ ခု)၊ ဆင်ကြင်း ၁: အမြင့်ဆုံး=42၊ 12 နှင့်လဲလှယ် → [27, 12, 33, 42]၊ 42 ကိုဖယ်ရှား (၃ ခုကျန်)၊ ဆင်ကြင်း ၂: အမြင့်ဆုံး=33၊ နောက်ဆုံးတွင်ရှိနှင့်ပြီး → [27, 12, 33]၊ 33 ကိုဖယ်ရှား (၂ ခုကျန်)၊ ဆင်ကြင်း ၃: အမြင့်ဆုံး=27၊ 12 နှင့်လဲလှယ် → [12, 27]၊ 27 ကိုဖယ်ရှား (၁ ခုကျန်)၊ ဆင်ကြင်း ၄: အမြင့်ဆုံး=12၊ နောက်ဆုံးတွင်ရှိနှင့်ပြီး → [12]၊ 12 ကိုဖယ်ရှား (၀ ကျန်) → ပြီးဆုံး၊ စုစုပေါင်း: အကြိမ် ၄ ကြိမ် လုပ်ဆောင် → ရွေးချယ်မှု ウ။