Final review 5/15/2017
Final exam:
Thu 5/18, 7pm-10pm, MBH 505 OR
Fri 5/19, 9am-noon, MBH 505
- What you are allowed to use:
- The final exam cheat sheet
- 2 sheets of notes, double-sided
- otherwise closed books, closed notes, no computers / devices
- practice exam is posted on course webpage, solutions will be posted by Tuesday evening
The exam is cumulative, with emphasis on the topics since the midterm:
- sets
- dictionaries
- tuples
- matplotlib
- writing modules
- module docstrings
- running vs. importing
- terminal
- navigating the file system
- running python programs
- passing command-line parameters to a program (sys.argv)
- reading data from the web (URLs)
- recursion
- matlab
- writing functions
- returning values
- efficiency
- R basics
- searching, sorting, big-O
- binary numbers
- misc
- optional/default parameters
Type of questions will be similar to midterm
- what's wrong with this code type questions
Also review problem sets and solutions
========================================================
Sample questions
- Rewrite the following function to improve the style:
def longwinded(a, b, c):
if a > b:
if a > c:
return True
else:
return False
else:
return False
- What does the following function do (in one sentence) assuming x is a list:
def mystery(x):
if len(x) <= 1:
return True
else:
if x[0] > x[1]:
return False
else:
return mystery(x[1:])
- Write a function that takes two parameters: a dictionary and a
number. The function should add the number to each value in the
dictionary.
- Write a matlab function called sum_first that takes a matrix as a
parameter and returns the sum of the first column of the matrix
- Write a function that takes a string as a parameter and returns the
string with all the uppercase letters removed. Hint, the isupper()
method may be useful.
- Write a recursive function all_upper that takes a list of strings as
a parameter and returns a list of booleans, True for strings in the
list that are all uppercase, False otherwise. Recall that the string
class has an isupper() method that checks if it is all uppercase.
- What decimal numbers are represented by the following binary numbers:
a. 1101
b. 111
c. 10010
- Convert the number 30 to binary
- Write a Matlab statement to generate the following matrix:
0 0 0 2 2 2
0 0 0 2 2 2
0 0 0 2 2 2
- Suppose you want to find a number in an unsorted list with N
elements. Provide runtimes in Big-O notation for the following two
strategies. What is faster?
a. Use linear search
b. Sort the list using merge sort, then use binary search
- Repeat the previous problem, but now assume you have to search
for N different numbers.
- Sort the following complexity classes from fastest to slowest:
O(N), O(N log N), O(log N), O(1), O(N^2)