Assignment 06

Contents:

  • Overview
  • Internet Requirements
  • Practice Problems
  • Problems to be Submitted
  • Extra Credit

  • Overview

    Topic: Algorithms
    Related Reading: Ch. 4.1-4.2 and 4.4-4.6 of [Br].
    Due: 8pm Monday, 22 October 2001

    Internet Requirements

    You will only need an internet connection at the time of submission.

    Practice Problems

  • Question 3 of Ch. 4.4 (p. 195 [Br])
    answers appear in Appendix F

  • Question 2 of Ch. 4.5 (p. 206 [Br])
    answers appear in Appendix F

  • Chapter Review Problem 26 (p. 220 [Br])

  • Consider the following sorted list of numbers:

    2 4 7 10 13 16 17 20 24 28 31 38 41 43 45

  • What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 28?

  • What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 16?

  • What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 5?
  • Note: The solution for the above questions can be found by using our Binary Search Demonstration and running with parameter "#items: 15" and "seed: 15849" and with target set appropriately.

  • Chapter Review Problem 19 (p. 219 [Br])

  • Problems to be Submitted (20 points)

    1. (5 points)
      Many things in our daily lives involve written instructions (e.g., preparing food, setting the clock on the microwave, ordering a product from a catalog). We want you to look around for such instructions so that we can see whether these constitute an algorithm based on the definition given in Figure 4.1 on page 169 of the Brookshear text.

      Find something in your life that contains written instructions and type these instructions, exactly as they appear (please select something so that your instructions take up at least a third of a page, but at most one whole page when typed.)

      Now, consider the definition of an algorithm, as given in Figure 4.1 on page 169 of the Brookshear text. Evaluate whether or not you feel that the instructions constitute an "algorithm" by this definition, explaining your thoughts.

    2. (5 points)
      Suppose the insertion sort as presented in Figure 4.11 (p. 194 [Br]) was applied to the list
        Frank
        Bob
        Carol
        George
        Alice
        Elaine
      
      Describe the organization of the list at the end of each execution of the body of the outer while structure.

    3. (5 points)
      Imagine that we are searching the list {A, B, C, D, E, F, G}. Please fill in the following table specifying the number of list items which are compared to the Target for each search:

      target sequential search binary search
      A    
      B    
      C    
      D    
      E    
      F    
      G    

    4. (5 points)
      Consider the following sorted list of numbers:

      1 2 9 11 12 13 15 26 23 24 29 34 35 41 43

    5. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 6?

    6. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 11?

    7. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 12?

    8. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 19?

    9. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 41?
    Overall, please place your answers to all of these questions in a single document to be submitted.

    Extra Credit (2 points)

    Read Chapter Review Problem 26 (p. 220 [Br]) which discusses a puzzle called the Tower of Hanoi. For notation, we will assume that the three pegs are named A, B, and C, and that the rings are numbered 1, 2, 3, and so on, starting with the smallest ring being 1.

    The recursive solution to the problem can be expressed with the following pseudocode:

      procedure Transfer(numRings, startPeg, endPeg, tempPeg)
        if (numRings > 0) 
          then
            [
             Apply Transfer(numRings-1, startPeg, tempPeg, endPeg)
            ]
            Move single Ring #numRings from startPeg to endPeg
            [
             Apply Transfer(numRings-1, tempPeg, endPeg, startPeg)
            ]
    
    Your job is to trace through the various activations of this recursive algorithm when it is intially called as Transfer(4,A,C,B). To demonstrate your understanding, your submission should include the ordered list of single moves which take place during the process.

    For example, if we called Transfer(2,A,C,B) the process is:

      Move ring #1 from A to B
      Move ring #2 from A to C
      Move ring #1 from B to C
    


    comp150 Class Page
    mhg@cs.luc.edu
    Last modified: 11 October 2001