Solutions to review questions: -------------- def longwinded(a, b, c): return a > b and a > c -------------- mystery(x) returns whether the list is sorted -------------- def add_to_dict(dict, num): for key in dict: dict[key] += num -------------- function result = sum_first(m) col_sums = sum(m); result = col_sums(1); % alternate one-line solution: % result = sum(m(:, 1)) % extract first column, return its sum -------------- def remove_upper(s): res = '' for c in s: if not c.isupper(): res += c return res -------------- def all_upper(str_list): if str_list == []: return [] else: return [str_list[0].isupper()] + all_upper(str_list[1:]) # non-recursive version for partial credit: def all_upper_nonrecursive(str_list): res = [] for str in str_list: res.append(str.isupper()) return res -------------- a. 13 b. 7 c. 18 -------------- 11110 -------------- [zeros(3), 2 * ones(3)] -------------- a. O(N) b. O(N log N) + O(log N) = O(N log N) (the first term dominates) linear search (a) is faster -------------- a. N * O(N) = O(N^2) b. O(N log N) + N * O(log N) = O(N log N) sorting once, then N * binary search (b) is faster -------------- O(1) fastest O(log N) O(N) O(N log N) O(N^2) slowest --------------