Sei sulla pagina 1di 4

T.

Dunson
COS-241
WA-5

Chapter 8
12. (a) There are 5 levels in the tree numbered 0 through 4.
(b) 11, 29, and 62
(c) Levels 0 and 1.
(d) Maximum height tree would have 13 levels (root node containing 11 and tree
skewed to the right, or root node containing 69 and tree skewed to the left).
(e) Minimum height tree would have 4 levels. (There are a number of possible
trees.)

13. (a) The path would go through the nodes containing 56, 69, 59, 62, and 61.
(b) The path would go through the nodes containing 56, 47, 22, 29, and 23,
before determining that 28 is not in the tree.

14. (a) 11 22 23 29 30 47 49 56 59 61 62 64 69
(b) 11 23 30 29 22 49 47 61 64 62 59 69 56
(c) 56 47 22 11 29 23 30 49 69 59 62 61 64

15.

16.
Chapter 9

2. (a) Any negative number can be used as a dummy value.


(b) Assume that the dummy value is -1.0.
tree
5.(a) True. Its smallest child index would be 85, but the tree only contains 85
elements.
(b) False. treeNodes[41] has two children: treeNodes[83] and
treeNodes[84].
(c) False. The left child of treeNodes[12] is treeNodes[25].
(d) True.
(e) False. The tree contains six full levels (containing 63 elements), with 22
additional elements on the seventh level.

6.
[7] C OR D
[8] D C
[9] A A

10. (a) The member functions would not change, but the private data members
would change. The only data member would be a pointer to a linked lists.
(b) The code for SortedType::InsertItem (linked implementation) can be
used directly with the relational operator reversed.
(c) The code is identical to StackType::Pop.
(d) Dequeue for a priority queue implemented as a linked list (ordered from
highest to lowest priority) is very simple and efficient; we have direct access to
the largest element. There is less work involved in fixing the structure after the
largest element is removed, because the next-largest element immediately
follows it. Thus the operation is 0(1). In the heap implementation we have
immediate access to the largest element, but we have to perform a reheap
operation to fix the structure, resulting in an O(log2N) operation. The linked list
implementation is more efficient, in terms of Big O.
When the priority queue is implemented as a linked list, the efficiency of
Enqueue varies according to the position that the new element occupies in the
list. If the new element belongs in the last position, the whole list is searched
before the insert place is found. Thus the operation is O(N). Using heaps, the
insertion operation is O(log2N). The linked list implementation might be better if
the elements were inserted in largely sorted order from smallest to largest value.
15. (a) The string length attribute is used to determine their priority (longer length
is higher priority).
(b)

Potrebbero piacerti anche