Assignment 1

This homework is worth 10 points.

When you finish this assignment you should be able to :

The answers to this homework must be typed and turned in at the beginning of class on the day it is due.
  1. [1 point] Give the definition of an algorithm.
  2. [1 point] How are algorithms used in the development of programs?
  3. [1 point] Is the following an algorithm? Why or why not.
  4. [1 point] Describe the difference between an algorithm and a set of rules.

      Go Fish.

      An algorithm to play Go Fish

    1. One player is the dealer.
    2. Each player is dealt five cards
    3. The remaining cards are placed in the center of the table, face down, spread out. This is called the pool.
    4. The player to the left of the dealer goes first.
    5. At the end of each turn, play passes to the left.
    6. On a turn the player
      1. Selects another player, the victim
      2. Asks the victim if they have any cards of a given type
      3. If the victim has any cards of that type, they must hand them over to the player
      4. If the victim does not have any cards of that type they respond with "Go Fish"
      5. If the victim says "Go Fish", the player selects a card at random from the pool
      6. If the player receives a card they requested, from the victim or from the pool, the turn continues, otherwise it is over.
    7. If a player ever has all four of the same card, it is a book and all four cards are placed face up in front of the player.
    8. If a player ever runs out of cards, they draw five cards from the pool.
    9. The game is over when all 13 books have been played.
    10. The winner is the player, or players with the most books.
    11. The player may not request a card they do not hold in their hand.
  5. [1 point] Is the following an algorithm? Why or why not.

      Password

      An algorithm to guess a password

    1. While the password is not found
      1. Pick a number n between 1 and 20
      2. Select n random letters, digits and symbols
      3. Check to see if these are the password
  6. [1 point] Is the following an algorithm? Why or why not.

      Tea Time

      An algorithm to brew a cup of tea.

    1. Fill the teapot with water
    2. Light the largest burner on the stove
    3. Place the teapot on the burner
    4. Place two sugar cubes in a teacup.
    5. Place a tea bag in the teacup
    6. Wait until the water in the teapot boils
    7. Pour the water from the teapot into the teacup.
    8. Wait 3 minutes
    9. Remove the teabag
    10. Stir to dissolve the sugar
  7. [2 points] Write an algorithm to determine if a positive integer is prime. Assume you do not have a list of prime numbers.
  8. [2 points] Write an algorithm which describes how to send a letter through the U.S. Post Office.