Assignment 07

Contents:

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

  • Overview

    Topic: Algorithms
    Related Reading: Ch. 6.1, 9.4, 9.5 and pp. 518-525
    Due: 9am Thursday, 1 August 2002

    Internet Requirements

    You will need an Internet connection for completing the assignment as well as submission.

    Practice Problems

  • Exercise 7 of Ch. 6 (p. 182); answer in back of text

  • Exercise 13 of Ch. 6 (p. 182); answer in back of text

  • Exercise 11 of Ch. 9 (p. 314); answer in back of text

  • Exercise 14 of Ch. 9 (p. 315); answer in back of text

  • Exercise 16 of Ch. 9 (p. 315); answer in back of text

  • 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 are compared to the target when performing binary search with target 28?

  • What sequence of 'middle' values are compared to the target when performing binary search with target 16?

  • What sequence of 'middle' values are compared to the target when performing binary search with target 5?
  • Note: The solution for the above questions can be found by running a Binary Search Demonstration with parameter "#items: 15" and "seed: 15849" and with target set appropriately.


  • Problems to be Submitted (20 points)

    1. (4 points)
      Exercise 12 of Ch. 9 (p. 314)

    2. (5 points)
      Exercise 13 of Ch. 9 (p. 314)
      Though it does not state this explicitly, please answer this question in reference to the Quicksort algorithm

    3. (5 points)
      Variant of Exercise 15 of Ch. 9 (p. 315). For this problem, do not just report the number of comparisons, rather report the exact sequence of items against which the target was compared.

    4. (3 points)
      What is the output generated when the following recursive routine is called as Test1(1):
        Test1(Count)
           if (Count<5) then
              print Count
              call Test1(Count+1)
           endif
      

    5. (3 points)
      What is the output generated when the following recursive routine is called as Test2(1):
        Test2(Count)
           if (Count<5) then
              call Test2(Count+1)
              print Count
           endif
      
    Overall, please type your answers to all of the problems in a single document to be submitted electronically. Please see details about the submission process.

    Extra Credit (2 points)

    The goal here is to really challenge your understanding of recursive procedures. A classic problem, known as the Towers of Hanoi can be solved with the following recursive procedure:
    Towers(n,A,B,C)
      if (n>0) then
        Call Towers(n-1,A,C,B)
        Print "Move ring <n> from <A> to <C>"
        Call Towers(n-1,B,A,C)
    

    To prove your understanding, please describe the precise output which is generated when a call is made as Towers(4,X,Y,Z).


    ns121 Class Page
    visprof@coloradocollege.edu