Algorithmic Complexity and Probability Flashcards
One way to measure how long a program takes to run is by timing it. But that would not be particularly informative, because the result would depend upon:
…
- the speed of the computer
- the efficiency of the Python implementation on that machine
- the value of the input
How can one evaluate the efficiency of programs? (3 ways)
- measure with a timer
- count the operations
- abstract notion of order of growth
States some downsides of timing programs.
Time does vary between algorithms, but it does not vary between implementations and computers
Downsides of counting operations?
Counting depends on the algorithm, but it does not depend on implementations, and there is no clarity in which operations to count.
Let’s say that we want to evaluate a function and we want to express efficiency in terms of size of input:
for i in L:
if i == e;
return True
return False
Analyze the first, worst and the average case scenarios in this case.
BEST CASE: first element is e
- minimum running time over all possible inputs of a given size, len(L)
AVERAGE CASE: look through about half of the elements of the list
- average running time over all possible inputs
WORST CASE: element e is not in the list
- maximum running time over all possible inputs of a given size, len(L)
What does “Big Oh” measure?
Big Oh measures the asymptotic growth, often called the order of growth.
Describes how the amount of time needed grows as size of the (input to) problem grows.
Big Oh is used to describe the ______ case.
a. best
b. worst
c. average
b. worst
Big Oh expresses the rate of growth of the program relative to the input size. True or false?
True
Big Oh evaluates the algorithm, the machine and the implementation. True or False?
False
What running times do the following denote?
a. O(1)
b. O(logn)
c. O(n)
d. O(nlogn)
e. O(nˆc)
f. O(cˆn)
a. the constant running time
b. the logarithmic running time
c. the linear running time
d. the log-linear running time
e. the polynomial running time (c is a constant)
f. the exponential running time (c is a constant being raise to a power based on the size of the input)
Rank the algorithm orders based on their time to execute:
O(1) O(logn) O(n) O(nlogn) O(nˆc) O(cˆn)
They are in perfect order.
The constant complexity is dependent on input. True or false?
False.
Simple iterative loop algorithms are typically linear in complexity. True or false?
True
Nested loops describe quadratic complexity. True or false?
True
Bisection search is an example of quadratic complexity. True or false?
False, bisection search is an example of logarithmic complexity.