Name____________________ net-id _________ Name____________________ net-id _________ Name____________________ net-id _________
mode_compA what's the value assigned to
mindex?
occs (an integer).
occs at which the largest value of
occs occurs (an integer).
m occurs in occs
(an integer).
mode_compA which is the most relevant as to why the function
works correctly.
nums[i] is the value
stored in occs[i], for 0 <= i < len(nums).
nums, but
the count of this number only occurs once in occs.
max works on integer values, string
values, and list values --- i.e., it would return the
largest list in a list of lists.
mode_compB and
mode_compC (in as few words as possible).
mode_compD
why is the value mn subtracted from n in the loop and
added to mindex in the return statement?
mn helps ensure that the code will work with
lists of string values as well as lists of int values.
nums has
its count stored in counts[0], i.e., the use of
nm
maps the lowest value in nums to zero and vice-versa.
mn is to ensure symmetry with
the use of mx.
Several runs of the program are shown below (from ola's macbook pro):
| Run with n = 10,000 | Run with n = 20,000 | Run with n = 30,000 |
|---|---|---|
|
|
|
|
The function mode_compD has these timings for
larger values of n (the number of elements in the list):
| n | time |
|---|---|
| 100,000 | 0.03 |
| 200,000 | 0.07 |
| 300,000 | 0.10 |
| 400,000 | 0.13 |
| 500,000 | 0.16 |
mode_compD and mode_compB for a
list with one million elements.
These questions are for the code in SetTimings.py
create_word do?
"etaoins", but returns a list.
"etaoins", and returns the string.
diffB?
.count(word) is applied
to the part of words before the occurrence of
word.
.count(word) is applied
to the part of words after the occurrence of
word.
words so that words
is not modified by the function diffB.
diffA and diffB
to run on a 20,000 element list, justify your answer.
linear_search named that?
if i in nums
check to (possibly) examine all values of nums
bisect.bisect_left returns
the least or left-most index where the parameter being searched for does
occur, if it occurs at all.
If the
value is len(nums) the value cannot occur in the list
nums. What's the purpose of the compound
if statement in binary_search?
i is not found in list nums.
i occurs, but ensures that
any index of list nums is valid, i.e., will not generate an
index-out-of-bounds exception.
index != len(nums) is un-needed, the
code would work without the check.
linear_search function to search
for 20,000 elements in a list of 40,000 elements? Justify.