Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Elementary sorting

1.[3p]

How many inversions does the array 5, 2, 4, 6, 1, 3 contain?

CorrectNot quite: 9

2.[3p]

Insertion sort's number of moves is exactly equal to

Correct
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?

CorrectNot quite: 499500

4.[2p]

A random permutation of n elements has, on average, how many inversions?

Correct
The answer is: $n(n-1)/4$
The answer is: $n(n-1)/4$
The answer is: $n(n-1)/4$

5.[3p]

Which of these are true of selection sort?

Select all that apply

Correct
Correct
Correct
The answer is: It makes the same number of comparisons on every input of a given size, It makes at most $n-1$ 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

Correct
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 O(n).

Correct
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?

CorrectNot quite: 80

9.[3p]

Any algorithm that only swaps adjacent elements is stuck at Θ(n2) on random input because

Correct
The answer is: each adjacent swap removes at most one inversion, and there are $\Theta(n^2)$ of them
The answer is: each adjacent swap removes at most one inversion, and there are $\Theta(n^2)$ of them
The answer is: each adjacent swap removes at most one inversion, and there are $\Theta(n^2)$ of them