AlgDes Ch02: Algorithm Analysis Questions With
Answers
Question 1.
What are the 2 most important tools for comparing the efficiency of algorithms without
implementing them?
Correct Answer: (1) The Random Access Machine (RAM) model of computation,
and (2) the asymptotic analysis of worst-case complexity.
Question 2.
Describe the Random Access Machine model.
Correct Answer: Each simple operation and each memory access take exactly
one time step. Loops and subroutines are not considered simple operations. We
have as much memory and the model doesn't take notice of whether an item is
in cache or on the disk.
Question 3.
What additional assumption allows running times to be computed using the RAM model?
Correct Answer: That the RAM executes a constant number of steps per second.
Question 4.
What are 3 benefits of using the RAM model?
Correct Answer: 1) It allows algorithms to be understood, studied, and
compared in a language-and machine-independent (but not
implementation-independent) manner; 2) it is simple to work with, and 3)
almost never gives misleading results.
Question 5.
What are the 3 algorithm complexity functions and how are they defined?
Correct Answer: (1) Worst-case complexity is defined as the maximum number
of steps performed by the algorithm, taken over all possible input instances for
a given instance size; (2) Best-case complexity is defined as the minimum
number of steps performed by the algorithm, taken over all possible input
instances for a given instance size; and (3) Average-case complexity is defined
as the average number of steps performed by the algorithm, taken over all
possible input instances for a given instance size.
Question 6.
Which of the 3 algorithm complexity functions is most commonly used, and why?
Correct Answer: Worst-case complexity, mostly because of the ambiguities in
working with Average-case complexity. In particular, it is usually difficult to
determine how "average" a particular instance is beforehand, and it may not be
obvious what sorts of instances produce near-worst-case performance.
,Question 7.
What are 2 reasons why it is very difficult to work with the exact algorithm complexity
functions?
Correct Answer: (1) They have too many bumps, and (2) They require too much
detail to specify precisely (becomes implementation-specific, and provides very
little additional information).
Question 8.
What is 1 reason why multiplicative constants are ignored using Big Oh analysis?
Correct Answer: They are language- and machine-dependent.
Question 9.
What is the exact definition of f(n) = O(g(n))?
Correct Answer: c times g(n) is an upper bound on f(n). Thus there exists some
constant c such that f(n) is always <= c times g(n), for large enough n. I.e., for
big enough problems, there is a constant c such that f(n) is always less than c
times g(n).
Question 10.
What is the exact definition of f(n) = Omega(g(n))?
Correct Answer: c times g(n) is a lower bound on f(n). Thus there exists some
constant c such that f(n) is always >= c times g(n), for large enough n. I.e., for
big enough problems, there is a constant c such that f(n) is always greater than
c times g(n).
Question 11.
What is the exact definition of f(n) = Theta(g(n))?
Correct Answer: It's basically a combination of both O and Omega, meaning
that two different multiplicative constants of g(n) provide upper and lower
bounds of f(n) above a certain problem size. So g(n) provides a nice, tight
bound on f(n).
Question 12.
What's the take home lesson regarding Big Oh notation?
Correct Answer: The Big Oh notation and worst-case analysis are tools that
greatly simplify our ability to compare the efficiency of algorithms. The enable
us to ignore the details and focus on the big picture.
Question 13.
n^2 = O(n^3). What is a better way to read the "=" in this case?
Correct Answer: "... one of the functions that are..."
Question 14.
Why is 2^(n+1) = Theta(2^n)?
Correct Answer: The key observation is that 2^(n+1) = 2 times 2^n. So it
doesn't grow faster than 2^n, but instead is always double. I think the mistake
is picturing 2^n in a similar way to how we think of x^n. In the former, n is the
variable. In the latter, n is fixed.
Answers
Question 1.
What are the 2 most important tools for comparing the efficiency of algorithms without
implementing them?
Correct Answer: (1) The Random Access Machine (RAM) model of computation,
and (2) the asymptotic analysis of worst-case complexity.
Question 2.
Describe the Random Access Machine model.
Correct Answer: Each simple operation and each memory access take exactly
one time step. Loops and subroutines are not considered simple operations. We
have as much memory and the model doesn't take notice of whether an item is
in cache or on the disk.
Question 3.
What additional assumption allows running times to be computed using the RAM model?
Correct Answer: That the RAM executes a constant number of steps per second.
Question 4.
What are 3 benefits of using the RAM model?
Correct Answer: 1) It allows algorithms to be understood, studied, and
compared in a language-and machine-independent (but not
implementation-independent) manner; 2) it is simple to work with, and 3)
almost never gives misleading results.
Question 5.
What are the 3 algorithm complexity functions and how are they defined?
Correct Answer: (1) Worst-case complexity is defined as the maximum number
of steps performed by the algorithm, taken over all possible input instances for
a given instance size; (2) Best-case complexity is defined as the minimum
number of steps performed by the algorithm, taken over all possible input
instances for a given instance size; and (3) Average-case complexity is defined
as the average number of steps performed by the algorithm, taken over all
possible input instances for a given instance size.
Question 6.
Which of the 3 algorithm complexity functions is most commonly used, and why?
Correct Answer: Worst-case complexity, mostly because of the ambiguities in
working with Average-case complexity. In particular, it is usually difficult to
determine how "average" a particular instance is beforehand, and it may not be
obvious what sorts of instances produce near-worst-case performance.
,Question 7.
What are 2 reasons why it is very difficult to work with the exact algorithm complexity
functions?
Correct Answer: (1) They have too many bumps, and (2) They require too much
detail to specify precisely (becomes implementation-specific, and provides very
little additional information).
Question 8.
What is 1 reason why multiplicative constants are ignored using Big Oh analysis?
Correct Answer: They are language- and machine-dependent.
Question 9.
What is the exact definition of f(n) = O(g(n))?
Correct Answer: c times g(n) is an upper bound on f(n). Thus there exists some
constant c such that f(n) is always <= c times g(n), for large enough n. I.e., for
big enough problems, there is a constant c such that f(n) is always less than c
times g(n).
Question 10.
What is the exact definition of f(n) = Omega(g(n))?
Correct Answer: c times g(n) is a lower bound on f(n). Thus there exists some
constant c such that f(n) is always >= c times g(n), for large enough n. I.e., for
big enough problems, there is a constant c such that f(n) is always greater than
c times g(n).
Question 11.
What is the exact definition of f(n) = Theta(g(n))?
Correct Answer: It's basically a combination of both O and Omega, meaning
that two different multiplicative constants of g(n) provide upper and lower
bounds of f(n) above a certain problem size. So g(n) provides a nice, tight
bound on f(n).
Question 12.
What's the take home lesson regarding Big Oh notation?
Correct Answer: The Big Oh notation and worst-case analysis are tools that
greatly simplify our ability to compare the efficiency of algorithms. The enable
us to ignore the details and focus on the big picture.
Question 13.
n^2 = O(n^3). What is a better way to read the "=" in this case?
Correct Answer: "... one of the functions that are..."
Question 14.
Why is 2^(n+1) = Theta(2^n)?
Correct Answer: The key observation is that 2^(n+1) = 2 times 2^n. So it
doesn't grow faster than 2^n, but instead is always double. I think the mistake
is picturing 2^n in a similar way to how we think of x^n. In the former, n is the
variable. In the latter, n is fixed.