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?
3.[2p] Which of these does the RAM model assume?
Which of these does the RAM model assume?
Select all that apply
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.
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
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