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?
How many comparisons does the nested-loop duplicate check, which compares every element with every later one, perform on a list of 200 numbers?
2.[2p] Why is timing a program with a stopwatch a poor way to compare two algorithms?
Why is timing a program with a stopwatch a poor way to compare two algorithms?
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?
Which of these does the RAM model assume?
Select all that apply
The answer is: Reading any memory cell costs one step, whatever its address, Arithmetic on a value costs one step, Memory is unbounded
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?
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?
5.[2p] An average-case cost is meaningful only once the distribution of inputs it averages over has been stated.
An average-case cost is meaningful only once the distribution of inputs it averages over has been stated.
The answer is: True
6.[3p] Testing whether an integer is prime by trying all divisors up to is called exponential rather than cheap because
Testing whether an integer is prime by trying all divisors up to is called exponential rather than cheap because
The answer is: the input is the written number, of size about bits, and is exponential in that size
The answer is: the input is the written number, of size about bits, and is exponential in that size
The answer is: the input is the written number, of size about bits, and is exponential in that size
7.[2p] Match each case to what it reports.
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 comparisons per second. How many seconds does a program costing comparisons take on ?
A machine performs comparisons per second. How many seconds does a program costing comparisons take on ?
9.[2p] The exact count is discarded in favour of "grows like " because
The exact count is discarded in favour of "grows like " because
The answer is: the constant depends on the machine and the lower terms vanish in relative size as grows
The answer is: the constant depends on the machine and the lower terms vanish in relative size as grows
The answer is: the constant depends on the machine and the lower terms vanish in relative size as grows