Q7
(10): Given the following list of unsorted numbers:
43, 62, 28, 4, 29, 8, 3, 18
a) Please show the iterations of each of the following. How many comparisons were made
for each one of them.
Selection Sort
Insertion Sort
Bubble Sort
Quicksort
Q7 (10): What will be the output of the following program?
public static void insertionSort (int[] data)
{
for (int index = 1; index < data.length; index++)
{
int key = data[index];
int position = index;
while (position > 0 && data[position-1]>key)
{
data[position] = data[position-1];
position--;
}
System.out.println(position);
data[position] = key;
}
}
public static void main(String[] args) {
int[] arr = {34, 12, 37, 5, 19, 11};
insertionSort(arr);
}
Output: