Saint Louis University |
Computer Science 140
|
Dept. of Math & Computer Science |
Topic: Data Structures and Algorithms
Related Reading: Ch. 6.1, Ch. 9 and notes
Due:
8pm Monday, 5 November 2007
You may want an Internet connection for several practice problems. However you do not necessarily need the connection for completing the assignment, other than for submission.
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 the target key set appropriately.
The following data is 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. The "head" of the list is cell 11. A pointer value of 0 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 | Z | 15 | X | 11 | C | 13 | V | 1 | B | 0 | N | 5 | M | 7 | L | 9 |
You may also quiz yourself by playing with some demos:
Consider the following sorted list of numbers:
2 | 4 | 9 | 16 | 19 | 21 | 25 | 27 | 32 | 33 | 35 | 38 | 41 | 42 | 43 |
What sequence of 'middle' values are compared to the target when performing binary search with target 4?
What sequence of 'middle' values are compared to the target when performing binary search with target 17?
What sequence of 'middle' values are compared to the target when performing binary search with target 22?
What sequence of 'middle' values are compared to the target when performing binary search with target 34?
Fill in the missing values for the following memory contents in a way so that it represents a linked list containing the sequence of characters "ANSWER". Which cell is the head of your list?
Memory Contents (in decimal) |
Cell | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Value | R | W | E | S | A | N |
The following data is a representation of a linked list. The "head" of the list is at cell 7. A pointer value of 0 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 |
Give the sequence of characters contained in the linked list, beginning with the "R" stored at the head of the list in cell 7.
We would like you to insert the letter "G" into the linked list so that it is sequenced immediately following the letter "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.
Having inserted "G" from the previous step, please continue by performing a deletion of the entry containing "W" from the list. Please show the contents of all memory cells after the deletion has been performed.
For this problem, consider the binary search tree shown in Figure 9.19 on page 310 of the text.
If "michael" were inserted into this tree, where would the item be placed?
If "kim" were inserted into this tree, where would the item be placed?
If "jill" were inserted into this tree, where would the item be placed?
If "louis" were inserted into this tree, where would the item be placed?
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.
The extra credit involves gaining a deeper familiarity with the recursive procedure for printing the information in a binary tree, as described by the Print algorithm on p. 312. Though this is described in relation to a binary search tree, the procedure can be used on an arbitrary binary tree.
Your extra credit task is the following. We want you to trace through the recursive execution of the procedure Print when applied to the tree which is displayed in Figure 9.16 on p. 306.
As demonstrated in the chapter, the procedure Print will get applied many times with varying parameters. Also, there is a difference between the order in which nodes become the parameter for a call to the Print routine and the order in which nodes get written to output by the Write command.
Please give the exact sequence of calls to this routine, reporting
the root of each subtree in the order the applications are
applied. For example, the first call is to
The only output generated by the procedure is from the command Write within that routine. 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, "1" is NOT the first data in the output.