CS 111
Summer 2 2017

Quiz 2 Info

Quiz 2 Information

Quiz details

Material covered

The quiz will focus on the material that we have discussed in class from the beginning of the summer session through Monday, July 17th. This corresponds to the following readings:

* Chapter 3: sections 3.2, 3.3, and 3.6.1 (including the box on list
  comprehensions)
* Chapter 4: sections 4.1 and 4.2, and 4.3 (up to and including 4.3.4)

Note: You are not responsible for details from the case studies in the readings (e.g., the information about how RSA encryption works). However, you are responsible for the programming and problem-solving concepts that those case studies were used to illustrate.

In addition, you should be familiar with concepts that were introduced in the pre-class videos, in-class discussion, or on the homeworks that were not covered in the readings.

Preparing for the quiz

Additional practice problems

  1. Evaluate the following:

    1. [3 for x in range(6)]
    2. [2*y + 1 for y in [1, 3, 5, 7]]
    3. [x for x in range(3, 10) if x % 2 == 0]
    4. [len(w) for w in ['Go', 'Terriers']]
    5. [[w, len(w)] for w in ['Python', 'is', 'amazing!']]
  2. (Recall this function from quiz 1 preparations.) Write a function num_divisors(n) that returns the number of integers from 1 to n (inclusive) that divide n evenly. For example, num_divisors(42) should return 8, because 1, 2, 3, 6, 7, 14, 21, and 42 are all divisors of 42. Use a list comprehension.

  3. Use the above num_divisors(n) function in order to write a function most_divisors(lst) that takes in a list of integers lst and returns the integer from that list with the most divisors. For instance, most_divisors([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) should return 12. Use a list comprehension and a list-of-lists approach.

  4. Write a function longest_string(lst) that takes in a list of strings lst as input and returns the longest string from that list. For example, longest_string(['short', 'longer', 'sesquipedalian']) should return 'sesquipedalian'.

  5. Add the following two binary numbers:

       1 1 0 1
     1 0 1 1 1
    ----------
    
  6. Multiply the following two binary numbers:

       1 0 1 1
     1 1 1 0 1
    ----------
    
  7. Write the complete truth table for the boolean function XYZ + XYZ.

  8. 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
    
  9. Design the circuit for the function from the previous problem.

  10. 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, x1, x0, y1 and y0, and produce a true output if and only if the two-bit number x1x0 is greater than the two-bit number y1y0.