Sorting

AP Computer Science A· difficulty 4/5

835 192 Selection sort, pass 0 (find smallest)

Selection sort is applied to <code>{8, 3, 5, 1, 9, 2}</code>. After ONE pass (pass 0), what does the array look like?

  • A

    [3, 5, 1, 8, 9, 2]

  • B

    [1, 3, 5, 8, 9, 2]

    check_circle
  • C

    [3, 5, 1, 9, 2, 8]

  • D

    [1, 3, 5, 8, 2, 9]

Explanation

Pass 0 finds the minimum (1, at index 3) and swaps it with index 0, giving [1, 3, 5, 8, 9, 2]. The rest of the array is unchanged.

Want 10 more like this — adaptive to your weak spots?

Related questions