Elementary sorting
1.[3p] How many inversions does the array 5, 2, 4, 6, 1, 3 contain?
How many inversions does the array 5, 2, 4, 6, 1, 3 contain?
2.[3p] Insertion sort's number of moves is exactly equal to
Insertion sort's number of moves is exactly equal to
The answer is: the number of inversions in the input
The answer is: the number of inversions in the input
The answer is: the number of inversions in the input
3.[2p] How many comparisons does selection sort make on an array of 1000 elements that is already sorted?
How many comparisons does selection sort make on an array of 1000 elements that is already sorted?
4.[2p] A random permutation of elements has, on average, how many inversions?
A random permutation of elements has, on average, how many inversions?
The answer is:
The answer is:
The answer is:
5.[3p] Which of these are true of selection sort?
Which of these are true of selection sort?
Select all that apply
The answer is: It makes the same number of comparisons on every input of a given size, It makes at most swaps, It is the right choice when moving an element is far more expensive than comparing two
6.[3p] To order a table by department and, within each department, by surname, using a stable sort, you should
To order a table by department and, within each department, by surname, using a stable sort, you should
The answer is: sort by surname first, then by department
The answer is: sort by surname first, then by department
The answer is: sort by surname first, then by department
7.[2p] Insertion sort runs in linear time on input whose inversion count is .
Insertion sort runs in linear time on input whose inversion count is .
The answer is: True
8.[2p] An insertion sort takes 5.0 seconds on 100,000 random records. Roughly how many seconds does it take on 400,000 random records?
An insertion sort takes 5.0 seconds on 100,000 random records. Roughly how many seconds does it take on 400,000 random records?
9.[3p] Any algorithm that only swaps adjacent elements is stuck at on random input because
Any algorithm that only swaps adjacent elements is stuck at on random input because
The answer is: each adjacent swap removes at most one inversion, and there are of them
The answer is: each adjacent swap removes at most one inversion, and there are of them
The answer is: each adjacent swap removes at most one inversion, and there are of them