?

AP® Computer Science Principles

Free Version

Upgrade subject to access all content

Difficult

Selection Sort Algorithm

APCSP-QFPJVV

The following incomplete flow chart is for a well-known, if inefficient, sorting algorithm known as a selection sort.

Selection Sort Alogorithm

What should be put into box 1 and box 2 to complete this algorithm for sorting a list from smallest to largest?

A

(Box 1): find which is smaller, the element at the index or the first value in the list
(Box 2): if the element at the index is smaller, then swap with first value

B

(Box 1): find the largest element in the list between index and end of list
(Box 2): swap the largest element with the element at index

C

(Box 1): find smallest element in list between index and end of list
(Box 2): set index equal to the index of the smallest element

D

(Box 1): find smallest element in list between index and end of list
(Box 2): swap smallest element with element at index