Nathan Sprague
9/1/17
I need to write Python code to find the largest gap between any pair of numbers in a list:
def findMaxDiff(numbers):
maxDiff = 0
for n1 in numbers:
for n2 in numbers:
diff = n1 - n2
if diff > maxDiff:
maxDiff = diff
return maxDiff
Goal: develop a function that maps from input size to the number of steps
total = 0;
for (int i = 0; i < numbers.length; i++) {
total += numbers[i];
}
total = 0;
for (int i = 0; i < numbers.length; i++) {
for (int j = 0; j < numbers.length; j++) {
total += numbers[i];
}
\(\log_2 1 = 0\)
\(\log_2 2 = 1\)
\(\log_2 4 = 2\)
\(\log_2 8 = 3\)
...
\(\log_2 4,000,000,000 = ??\)
Consider the following (very) informal definitions:
A reasonably fast computer can perform 1,000,000,000 operations per second
A reasonably short period of time is one second
A program is good enough if it can process 1,000,000 items in a reasonably short period of time on a reasonably fast computer.
Assume that \(T(n)\) is a function that describes the number of operations required for program A. Select the first true statement from the following list.
Consider the following (very) informal definitions:
A reasonably fast computer can perform 1,000,000,000 operations per second
A reasonably short period of time is one second
A program is not totally useless if it can process 100 items in a reasonably short period of time on a reasonably fast computer.
Assume that \(T(n)\) is a function that describes the number of operations required for program A. Select the first true statement from the following list.