Homework 0

[Note: this webpage last modified Friday, 04-Feb-2011 19:44:51 EST]

This homework assignment is due before class starts on Tuesday, January 18. Your solutions should be explained in complete sentences such that your classmates will understand the solution (and can verify your proofs are correct) even if they have not solved the problems themselves.

  1. HW Polices.

    1. Type your HW (in word, latex, text file, etc.) and send to me by email.

    2. Do NOT share electronically. You must type your own solutions. You can discuss the problems with each other, but you may only discuss them. You may not write out solutions together.

    3. You MAY NOT search the Internet, textbooks, etc. for solutions to the problems. The following are the ONLY sources of information that you may use in solving the problems: the textbook for this course and assigned reading, and wikipedia articles on basic math/probability/CS/etc.. You may discuss the problems with each other and with myself, but must obey the previous item in doing so.

      If you do find the solution in one of these sources, you still MUST cite the source in your document.

      You may use NOTHING ELSE that is online or other textbooks.

    4. You MAY NOT copy word-for-word from any source, even the sourcesyou are allowed to consult. If you feel it is necessary, you should put the quotation in quotes and provide a reference/citation.

  2. (-3 points if left blank) List who you collaborated with on this assignment, "none" if none.

  3. (5 Points) Consider the following functions written in Python.

          # multiply the numbers x and y, assuming x and y are both 
          # positive integers
          def mult(x, y):
            if (x == 1):
              return y
            else:
              return mult(x-1,y)+y
    
          # add the numbers x and y, assuming x and y are both non-negative
          # integers
          def add(x, y):
            if (x == 0):
              return y
            else:
              return add(x-1,y)+1
        
    Compute the number of lines that are executed when executing mult(6, 6) and add(6, 6). Give a worst-case estimate for the number of lines executed for mult and add as a function of the number of bits in the input. Are these algorithms efficient? Are the traditional pencil and paper multiplication and addition algorithms more efficient?
  4. (5 Points) In your favorite programming language (Python, C, or whatever), write a program that does the following. It asks the user to input a message to encode. The user should enter a string of 0's and 1's, however long they want (you can assume it is less than 100 characters if you want). The program takes these 0's and 1's, and divides them into blocks of 7 (adding a few extra 0's to the end if necessary to make the length of the string a multiple of 7). Each block is then encoded by the Hadamard code that converts 7 bits into 2^7=128 bits. And all of these bits are output to the screen (or to a file, whichever you like). So you are writing the Hadamard encoding function. Optionally, you could also write the Hadamard decoding function, but you do not have to.