Solution

Data Structures

Problems to be Submitted (20 points)

  1. (4 points)

    1. BinarySearch(0,14) Middle: 7 blueberry < gooseberry
      BinarySearch(0,6) Middle: 3 blueberry < boysenberry
      BinarySearch(0,2) Middle: 1 blueberry > blackberry
      BinarySearch(2,2) Middle: 2 blueberry = blueberry
    2. BinarySearch(0,14) Middle: 7 carrot < gooseberry
      BinarySearch(0,6) Middle: 3 carrot > boysenberry
      BinarySearch(4,6) Middle: 5 carrot < currant
      BinarySearch(4,4) Middle: 4 carrot < cranberry
      BinarySearch(4,3)
    3. BinarySearch(0,14) Middle: 7 currant < gooseberry
      BinarySearch(0,6) Middle: 3 currant > boysenberry
      BinarySearch(4,6) Middle: 5 currant = currant
    4. BinarySearch(0,14) Middle: 7 kiwi > gooseberry
      BinarySearch(8,14) Middle: 11 kiwi < mulberry
      BinarySearch(8,10) Middle: 9 kiwi > huckleberry
      BinarySearch(10,10) Middle: 10 kiwi < loganberry
      BinarySearch(10,11)

  2. (3 points)

    Memory Contents
    (in decimal)
    Cell 1 2 3 4 5 6 7 8 9 10 11 12
    Value R 0 W 5 E 1 S 3 A 11 N 7
    The head is at Cell 9.

  3. (9 points)

    1. Sequence: R -> W -> Y -> T -> P -> Q

    2. Note: There are two possible correct answers to the next two parts, depending on which pair of empty cells are used for the newly inserted item. (cells [5,6] or [13,14] were available).

      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 G 15 R 3 T 5 Y 9 U 13 P 1

      or

      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 13 Y 9 G 15 P 1
    3. Again, depending on last part, answer should be

      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 G 15 R 11 T 5 Y 9 U 13 P 1

      or

      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 11 T 13 Y 9 G 15 P 1

  4. (4 points)

    I made a mistake in stating the original assignment (since corrected), as I errantly said to use the tree from "Figure 9.19 on page 320". This is a tree in Figure 9.19 on page 310 and there is a larger tree on page 320. Given the confusion, I'll accept answers based on either model.

    For the tree on page 310,

    1. "michael" would become the right child of "mari"

    2. "kim" would become the right child of "kate"

    3. "jill" would become the left child of "jim"

    4. "louis" would become the left child of "mari"

    For the tree on page 320,

    1. "michael" would become the left child of "nell"

    2. "kim" would become the left child of "kit"

    3. "jill" would become the right child of "christopher"

    4. "louis" would become the left child of "mari"


Extra Credit

    1. 1, 2, 4, 7, 3, 5, 8, 9, 6, 10

    2. 7, 4, 2, 1, 8, 5, 9, 3, 6, 10


Last modified: Friday, 04 April 2008