Assignment 08

Contents:

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

  • Overview

    Topic: Data Structures
    Related Reading: Ch. 7.1-7.2, 7.5 of [Br].
    (skip second half of p. 326 and all of p. 331).
    Due: 8pm Thursday, 28 March 2002

    Internet Requirements

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

    Practice Problems

  • Question 1-4 of Ch. 7.1 (pp. 324-325 [Br])
    answers appear in Appendix F
  • Chapter 7 Review Problems 5, 6, 7 (p. 362 [Br])
  • Chapter 7 Review Problem 13 (p. 363 [Br])
  • Question 1, 4, 5, 6 of Ch. 7.5 (p. 352 [Br])
    answers appear in Appendix F
  • Chapter 7 Review Problem 23 (p. 364 [Br])

  • Problems to be Submitted (20 points)

    1. (5 points)
      Consider representing the following two-dimensional array using 15 consecutive cells of memory. The placement of the individual characters depends on whether the array is represented in row major order or column major order.

      Q W E
      R T Y
      U I O
      P A S
      D F G

      1. How would the characters be arranged in memory if using row major order?
      2. How would the characters be arranged in memory if using column major order?
      3. Most characters do not remain in the same memory cell when switching from row major to column major order. However, there are three characters which do remain in the same cell, no matter which of the two orders is used. Which three characters?

    2. (9 points)
      The following data is actually a representation of a linked list. Each "node" of the list is represented using two cells of memory. The first of the two cells stores a letter of the alphabet and the second of the two cells stores a "pointer" to the cell of memory which begins the following node in the linked list.

      In this example, we will store a single character as the data for each node. The "head" of this particular list begins with the entry at cell 7. A pointer value of zero designates the end of the list.

      Memory Contents
      (in decimal)
      Cell 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
      Value Q 0 W 11 E 12 R 3 T 15 Y 9 U 13 P 1

      1. Give the sequence of characters contained in the linked list, beginning with the "R" stored at the head of the list in cell 7.
      2. We would like you to insert the letter "G" into the linked list so that it is sequenced between the letter "T" and the letter which originally follwed "T" in the list. (You may use any pair of cells for this new entry which were "unused" in the previous list). Please show the contents of all memory cells after the insertion has been performed.
      3. Having inserted "G" from the previous step, please continue by performing a deletion the entry containing "W" from the list. Please show the contents of all memory cells after the deletion has been performed.

    3. (3 points)
      Chapter 7 Review Problem 24 (pp. 364-365 [Br])

    4. (3 points)
      Chapter 7 Review Problem 28 (p. 365 [Br])
      The "diagram" you submit should be text which shows the memory cell numbers and contents, similar in spirit to Figures 7.19 and 7.20 (pp. 345-346 [Br]).

    Overall, please place your answers to all of these questions in a single document to be submitted.


    Extra Credit (2 points)

    The extra credit involves gaining a deeper familiarity with the recursive PrintTree procedure of Figure 7.24 of [Br]. Practice problems for this topic include Question 6 of Ch. 7.5 (p. 352 of [Br]), as well as Chapter 7 Review Problems 26 and 31 (p. 365 of [Br]).

    Your extra credit task is the following. We want you to trace through the recursive execution of the procedure PrintTree when applied to the tree which is displayed in Question 1 on page 352 of [Br]. (Note: you do not need to do that question, we simply wanted to use that tree as an example)

  • Because of the recursion, the procedure PrintTree(Tree) is applied many different times, on various subtrees of the original. Give the exact sequence of applications of this routine, reporting the root of each subtree, in the order the applications are applied.

    Hint: the first application is PrintTree(the tree rooted at "11").
    The second aplication is PrintTree(the tree rooted at "9").

  • The only output generated by the procedure is from the line "print the root node of Tree". In what order will the values be printed to output, when starting the process on the original tree?

    Hint: You will find that this is NOT the same order as you report for the previous question. For example, "11" is NOT the first output value.


  • comp150 Class Page
    mhg@cs.luc.edu
    Last modified: Mon Mar 18 21:22:28 CST 2002