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.

Counting the cost

1.[2p]

How many comparisons does the nested-loop duplicate check, which compares every element with every later one, perform on a list of 200 numbers?

CorrectNot quite: 19900

2.[2p]

Why is timing a program with a stopwatch a poor way to compare two algorithms?

Correct
The answer is: The result describes the machine, the language and the one input tried, none of which are properties of the algorithm
The answer is: The result describes the machine, the language and the one input tried, none of which are properties of the algorithm
The answer is: The result describes the machine, the language and the one input tried, none of which are properties of the algorithm

3.[2p]

Which of these does the RAM model assume?

Select all that apply

Correct
Correct
The answer is: Reading any memory cell costs one step, whatever its address, Arithmetic on a value costs one step, Memory is unbounded
Correct

4.[2p]

An array holds 400 distinct values, and the searched-for value is present and equally likely to be at any position. What is the expected number of comparisons for linear search?

CorrectNot quite: 200.5

5.[2p]

An average-case cost is meaningful only once the distribution of inputs it averages over has been stated.

Correct
The answer is: True

6.[3p]

Testing whether an integer N is prime by trying all divisors up to N is called exponential rather than cheap because

Correct
The answer is: the input is the written number, of size about $\log_2 N$ bits, and $\sqrt{N}$ is exponential in that size
The answer is: the input is the written number, of size about $\log_2 N$ bits, and $\sqrt{N}$ is exponential in that size
The answer is: the input is the written number, of size about $\log_2 N$ bits, and $\sqrt{N}$ is exponential in that size

7.[2p]

Match each case to what it reports.

  • Best case

  • Worst case

  • Average case

  • the expected cost under an assumed distribution

  • the smallest cost over all inputs of that size

  • the largest cost over all inputs of that size

Show the answer

Best case: the smallest cost over all inputs of that size Worst case: the largest cost over all inputs of that size Average case: the expected cost under an assumed distribution

8.[2p]

A machine performs 109 comparisons per second. How many seconds does a program costing n2/2 comparisons take on n=100{,}000?

CorrectNot quite: 5

9.[2p]

The exact count 1.5n2-1.5n+c is discarded in favour of "grows like n2" because

Correct
The answer is: the constant depends on the machine and the lower terms vanish in relative size as $n$ grows
The answer is: the constant depends on the machine and the lower terms vanish in relative size as $n$ grows
The answer is: the constant depends on the machine and the lower terms vanish in relative size as $n$ grows