CS302 Midterm Exam - October 13, 2015

Do your answers on the answer sheets provided. When you write code, you do not need to have "include" or "using" statements.

Question 1

For each of these answers, give me a numerical expression that only includes numbers, addition, subtraction, multiplication, division and/or exponentiation. I don't want factorials or more complex notation. It doesn't have to be completely reduced, or calculated out, but it should be clear.
   
main()
{
  int i, j, k;

  cin >> k >> j;
 
  for (i = 0; i < (1 << k); i++) {
    if (i & (1 << j)) printf("Yes\n");
  }
  exit(0);
}

Part A: If the program to the right receives "5 1" on standard input, how many lines will it print?

Part B: If the program to the right receives "8 0" on standard input, how many lines will it print?

Part C: If the program to the right receives "3 3" on standard input, how many lines will it print?

Part D: Suppose I have 7 cities, numbered 1 through 7, that I want to visit, starting with city 1. There is a road from each city to each other city, and I can only visit each city once. In how many different orders can I visit all of the cities?

Part E: Suppose I am playing fantasy football, and I need to select a team with four running backs and two quarterbacks. And suppose that there are 75 running backs and 32 quarterbacks to choose from. How many different teams can I choose?

Part F: In class, I went over a topcoder problem called SimpleRotationDecoder, where a three-letter, lower-case password was required to decode a string containing n lower-case letters and spaces. We didn't know the password, so we performed an enumeration. How many elements did we enumerate?