Midterm 2 Information
The exam will focus on the topics covered in lecture from the material on gates and circuits up to and including the material on references. The use of the stack and recursion in the context of assembly language will not be included on the exam.
Remember that you can access all of the relevant pre-lecture videos and lecture notes in the Lectures section of the course’s Blackboard site.
The exam will be held from 6:30-7:30 p.m. on Wednesday, November 14, in the following locations:
- A1 lecture (MWF 10:10-11:00):
- B1 lecture (MWF 12:20-1:10):
- C1 lecture (TuTh 11:00-12:15):
- students with special accommodations: MCS B08 (note the change)
The A1 and B1 sections will meet for lecture on the day of the midterm.
You must bring your BU ID to the exam, so that we can check it when you turn in your exam.
You will have the full 60 minutes for the exam.
We will provide a page with the full list of Hmmm instructions that you can use during the exam.
You may not use any other materials during the exam. In particular, you should turn off and put away cell phones, watches, and other devices.
The exam will include questions similar to the ones posed in lecture–both the Top Hat questions and the open-response ones. However, these questions will not be multiple-choice. You will need to determine and write the answer without a list of options to choose from.
In addition, there will be questions that ask you to write a function, a short program, or a simple circuit, similar to the problems from the homework.
Preparing for the exam
One way to prepare is to review the pre-lecture materials and lecture notes and make a summary of the key points in your own words. “Boiling down” the material in this way is a great way to ensure that you really understand the key concepts.
We also encourage you to do practice problems. Options include:
redoing the questions posed in lecture–both the clicker questions and the open-response ones. The online lecture notes include both the questions and–on the next slide–the answers.
the practice problems found below (Note: Solutions to these additional practice problems will be posted under Other Content on Blackboard as we get closer to the exam.)
the following questions from CodingBat:
Note: Some of these questions refer to an array, which is another name for a list.
When working on practice problems, try to come up with your answers on paper, rather than through a trial-and-error approach on IDLE or in another programming environment. This will be give you an experience that is similar to the one that you will have during the exam.
Feel free to post questions on Piazza (using the
midterm_exam2tag) or to email the course account (
Additional practice problems
Solutions to these problems will be posted under Other Content on Blackboard as we get closer to the exam.
Write the complete truth table for the boolean function XYZ + XYZ.
Given the following truth table, perform the minterm expansion for the function
f. Don’t simplify!
x y f(x,y) ------------- 0 0 1 0 1 0 1 0 1 1 1 0
Design the circuit for the function from the previous problem.
Add the following two binary numbers:
1 1 0 1 1 0 1 1 1 ----------
Multiply the following two binary numbers:
1 0 1 1 1 1 1 0 1 ----------
Design a truth table, minterm formula, and circuit that will implement a 2-bit greater-than function. Your function should take 4 bits of input,
y0, and produce a true output if and only if the two-bit number
x0is greater than the two-bit number
Write a Hmmm assembly-language program that gets two positive integers from the user, subtracts the second integer from the first, and writes out the square of the result.
Write a Hmmm assembly-language program that uses a loop to allow the user to enter one or more integers. When the user enters a zero, the program should stop looping and write out two counts: how many of the numbers were positive, and how many were negative. Don’t count the zero.
Write a Hmmm assembly language program that reads a positive integer
nfrom the user and calls a separate function
ntimes. The function should simply write out the number 111. You must use
jumprinstructions to implement your function.
Write a Python function
years_neededthat takes three inputs:
principal, which is the initial amount of money deposited in an interest-bearing account
rate, which is the annual interest rate in decimal form
target, which is the final value that the investor wants to reach
The function should use a loop to determine the number of years of compounded annual interest that are needed for the investment to reach or exceed the specified
target. Note: After each year, the new principal is computed as
principal = principal * (1 + rate)
Write a Python function
count_vowels(s)that counts and returns the number of vowels in a string. Use a loop.
Write a Python function
nis a positive integer. It should print
nlines of stars with 1 star on first line, 2 stars on second line, and so forth. For example,
* ** *** ****
Use nested loops. You are not allowed to use the
*operator (*). You should use
print('*', end= '')to print a single asterisk at a time while remaining on the same line, and an empty
print()to go down to the next line.
Write a function
all_perfect(lst)that takes a list of numbers
Trueif all of the numbers are 100 and
Falseotherwise. Use a loop.
Write a function
index_nearest(n, lst)that takes a number
nand a list of numbers
lstand returns the index of the element in
lstwhose value is closest to
n. Use one or more loops.
A two-part problem:
First, write a function
num_appearances(substring, s)that returns the number of appearances of the specified
substring(which you may assume is of length 2) in the string
s. Hint: Use an index-based loop.
Next, write a function
most_common_pair(s)that returns the two-character string in
sthat appears most often as a substring within
s. For example,
al. Ties may be broken arbitrarily. Hint: Use
num_appearancesas a helper function. In addition,
most_common_pairwill need its own index-based loop.
Optional challenge: Write a function
longest_dna(s)that takes a string
sand returns the longest substring that consists only of the characters ‘A’, ‘C’, ‘G’, and ‘T’. For example,
'GTTACTGGGC'. Ties may be broken arbitrarily.
What is printed by the following Python program?
def loopy(x, y): print('starting loopy:', x, y) while x < y: x += 1 y -= 2 print('after loop:', x, y) return x x = 1 y = 8 y = loopy(x, y) print('after first call:', x, y) loopy(y, x) print('after second call:', x, y)
Hint: Use two different tables – one for the global scope and one for
loopy– to keep track of the values of the variables.
Draw one or more memory diagram like the ones we have used in lecture to illustrate the execution of the following Python program:
a = [1, 2, 3, 4] b = a a = 5 b = 7 print('a is', a) print('b is', b)
In addition, write a few sentences that refer to your diagram(s) and that explain the result of the program.
Draw memory diagrams that demonstrate why we get different results from the following two Python programs:
### Program 1 ### def foo(a): a = 2 * a return b = [1, 2, 3] for i in range(len(b)): foo(b[i]) print('b is', b) ### Program 2 ### def bar(lst, i): lst[i] = 2 * lst[i] return b = [1, 2, 3] for i in range(len(b)): bar(b, i) print('b is', b)
In addition, write a few sentences that refer to your diagrams and that explain the difference in output.