# AP Computer Science A : Insertion Sort

## Example Questions

### Example Question #3 : Sorting

Which of the following statements explains insertion sort?

The list is broken apart into smaller lists that are sorted and merged back together.

All numbers less than the average are inserted on the left, and the rest is inserted at the right. The process is then repeated for the left and right side until all numbers are sorted.

The list is iterated through multiple times until it finds the desired first number, then repeats the process for all numbers.

It removes one element from the list, finds where it should be located, and inserts it in that position until no more elements remain.

None of these are insertion sort.

It removes one element from the list, finds where it should be located, and inserts it in that position until no more elements remain.

Explanation:

Insertion sort removes an element from a list, checks the values adjacent to it to see if it is greater or smaller, until it finds the position where the number to the left is smaller and the number to the right is larger and places it there.

### Example Question #1 : Insertion Sort

{1, 9, 5, 4, 2, 0, 4}

What would the set of numbers look like after four iterations of Insertion Sort?

{1, 4, 5, 9, 2, 0, 4}

{1, 4, 9, 5, 2, 0, 4}

{1, 4, 4, 9, 5, 2, 0}

{1, 9, 4, 5, 2, 0, 4}

{1, 4, 4, 5, 9, 2, 0}

{1, 4, 5, 9, 2, 0, 4}

Explanation:

Insertion Sort is a sorting algorithm that starts at the beginning of an array and with each iteration of the array it sorts the values from smallest to largest.

Therefore, after four iterations of Insertion Sort, the first four numbers will be in order from smallest to largest.

### Example Question #2 : Insertion Sort

Which of the following do we consider when choosing a sorting algorithm to use?

I. Space efficiency

II. Run time efficiency

III. Array size

IV. Implementation language

II, IV

II, III, IV

I, II, III

I, II

I, II, III, IV