Hello World - Spring 2007

Homework 2

Attempt by: Monday, January 29
Due by: Thursday, February 1

Reading

Practice Problems (not to turn in)

The following problems will give you extra practice with algorithms, but you do not need to turn them in. Do them as you do the reading. Solutions are given on pages 683-684, but don't look at the answers until you have tried working through them on your own.

Problems To Hand In

  1. Reread the box entitled "From Little Primitives Mighty Algorithms Do Grow" on the bottom of page 53 of the textbook. In a brief essay (can be as short as one paragraph and must be no more than one page), explain how this idea relates to reductionism, and, thus, connects computer science to more established sciences such as physics, chemistry, and biology.

  2. From the textbook, Chapter 2 (page 75): exercises 5, 7, and 11

  3. From the textbook, Chapter 2 (page 75): exercises 3 and 8

  4. From the textbook, Chapter 2 (page 75): exercises 4 and 9

  5. Consider the following algorithm:

     1. Get value for n (size of input list)
     2. Get values for L1, L2, ..., Ln
     3. Set value of mystery to 0
     4. Set value of i to 1
     5. While value of i < value of n do
     6.     Add value of Li to value of mystery
     7.     Add 1 to value of i
        (End of the loop)
     8. Print out value of mystery
     9. Stop
    
    1. Show the output of this algorithm if given the following list of numbers as input:
      15, 7, 11, 5   (n = 4)

    2. In ten words or less, explain what this algorithm does. Given that, suggest a more appropriate name for the variable mystery.

  6. Consider the following algorithm:

     1. Get value for m (size of list)
     2. Get values for W1, W2, ..., Wm
     3. Set value of j to be same as value of m
     4. While value of j is greater than 0 do
     5.     Print out value of Wj
     6.     Subtract 1 from value of j
        (End of the loop)
     7. Stop
    
    1. Show the output of this algorithm if given the following list of letters as input:
      G, N, I, K, R, U, L   (m = 7)

    2. In ten words or less, explain what this algorithm does.