Assignment 07

Contents:

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

  • Overview

    Topic: Algorithms
    Related Reading: See Lectures 16 & 17.
    Due: 8pm Thursday, 21 March 2002

    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

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

  • Question 1 of Ch. 4.6 (p. 216 [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. (4 points)
      Consider the following sorted list of numbers:

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

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

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

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

    5. What sequence of 'middle' values in considered when running the binary search algorithm (Figure 4.14 of [Br]) with target 41?
    6. (4 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.
      (please see solution to the first practice problem as an example)

    7. (4 points)
      Consider the selection sort, exactly as presented in the solution given on p. 572, for Question 5 of Section 4.4, when 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.

    8. (4 points)
      In lecture, we demonstrated the execution of the MergeSort routine on a sample list. Specifically, we showed the order of the characters after each activation of the procedure MergeLists completes.

      Please give a similar presentation when MergeSort is executed on the following initial list of characters:

      H  O  M  E  W  O  R  K
      

    9. (4 points)
      Chapter Review Problem 23 (p. 220 [Br])
    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 29 (p. 221 [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: 25 March 2002