Answer:
[An earlier version had the “1 + ” missing.]
int size (Node* root)
{
if (root == NULL)
return 0;
return 1 + size (root->left) + size (root->middle) + size (root->right);
}
10 8 6 2 1 4 5
8 5 6 2 1 4
Show it after another element has been removed and it has been made into a heap again.
6 5 4 2 1
Show it after one more element has been removed and it has been made into a heap again.
5 2 4 1
Starting with an empty hash table, show the picture around subscript 380 after each of the following operations:
insert 492 4380 Joe
insert 443 6380 Mary
insert 544 5380 Sue
delete 443 6380 Mary
| |
|-----------------|
380: | 492 4380 Joe |
|-----------------|
381: | |
|-----------------|
382: | |
|-----------------|
383: | |
|-----------------|
| |
|-----------------|
380: | 492 4380 Joe |
|-----------------|
381: | 443 6380 Mary |
|-----------------|
382: | |
|-----------------|
383: | |
|-----------------|
| |
|-----------------|
380: | 492 4380 Joe |
|-----------------|
381: | 443 6380 Mary |
|-----------------|
382: | 544 5380 Sue |
|-----------------|
383: | |
|-----------------|
| |
|-----------------|
380: | 492 4380 Joe |
|-----------------|
381: | XXXXXXXXXXXXXXX |
|-----------------|
382: | 544 5380 Sue |
|-----------------|
383: | |
|-----------------|
Each of the following proposed hash functions has a serious flaw. Very briefly describe the flaw.
Only a small part of the table ever gets used.
Still not a good use of the table but worse than that,
some subscripts will be outside the table.
Same problem as previous, aggravated.
Very poor usage of the table when the subscripts
are within range, and, worse, many subscripts are
outside the table.
bool Expression::linear ()
{
if (constant ())
return true;
if (op == 'x')
return true;
switch (op) {
case '+':
case '-':
return left->linear () && right->linear ();
case '*':
return
(left->linear () && right->constant ())
||
(left->constant () && right->linear ());
}
}
// assuming trees are pointers to tree nodes ...
bool balanced (TreeNode* t)
{
if (t == NULL)
return true;
return
abs (size (t->left) - size (t->right) <= 1
&&
balanced (t->left)
&&
balanced (t->right);
}
Bucket sort with a bucket for each time unit (e.g., minute).
What if you had to sort by subject?
Probably nothing much one can do other than use a general-purpose (i.e., comparison-based) sort such as quicksort.
© 2002 Karl Winklmann