The exam was two hours, pencil/paper only.
So, to find this question on your exam, look at the procedure name of "Part A" in theh first column of the table. Then go to the "Part" specified, and you'll find it.
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | p15f03 | Part A 321bf | p7b282 | Part J 4e73a | paa72f | Part G a8d0c | p72078 | Part B f7c0a | p7a352 | Part H
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | p43498 | Part B 321bf | p7a1a3 | Part H 4e73a | pebd45 | Part H a8d0c | pbbdf1 | Part J f7c0a | p230bf | Part D
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | p66a4e | Part C 321bf | p0cbfd | Part B 4e73a | p9c40c | Part J a8d0c | pa44b1 | Part I f7c0a | p52aef | Part G
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | pdd0d9 | Part D 321bf | p321bf | Part A 4e73a | p24559 | Part E a8d0c | p7c0fb | Part F f7c0a | pfb6a5 | Part C
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | pcfaee | Part E 321bf | pd0508 | Part G 4e73a | pa5697 | Part I a8d0c | pa8d0c | Part B f7c0a | p29433 | Part I
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | pbe62d | Part F 321bf | p81431 | Part D 4e73a | p4e73a | Part A a8d0c | p472d8 | Part H f7c0a | p3cafd | Part B
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | pf5a0d | Part G 321bf | pafcfa | Part I 4e73a | p8545b | Part D a8d0c | p57776 | Part E f7c0a | pf7c0a | Part A
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | p27964 | Part H 321bf | pfff8a | Part F 4e73a | p4f7e8 | Part B a8d0c | p98910 | Part C f7c0a | p4e779 | Part E
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | p3f6ff | Part I 321bf | pb5993 | Part C 4e73a | peac4c | Part C a8d0c | pa65fd | Part D f7c0a | pabc80 | Part F
Hash | Procedure Name | Part where you find the procedure ----- | -------------- | --------------------------------- 15f03 | pdfa14 | Part J 321bf | pb554d | Part E 4e73a | p54562 | Part F a8d0c | pfa1c3 | Part G f7c0a | p1f798 | Part J
![]() |
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | ----- | ------ C09759 | A | F | ( and ) | G | 1 C323a1 | C | D | + and - | E | 1 C57a16 | G | A | [ and ] | B | 1 C66c43 | C | G | + and - | H | 1 Cab167 | C | G | [ and ] | H | 1
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | ----- | ------ C09759 | B | F | ( and ) | (G(HI)) | 50100 C323a1 | B | D | + and - | +E+FG-- | 50100 C57a16 | C | A | [ and ] | [B[CD]] | 50100 C66c43 | D | G | + and - | +H+IJ-- | 50100 Cab167 | F | G | [ and ] | [H[IJ]] | 50100
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | ----- | ------ C09759 | C | F | ( and ) | (I) | 300 C323a1 | F | D | + and - | +G- | 300 C57a16 | A | A | [ and ] | [D] | 300 C66c43 | E | G | + and - | +J- | 300 Cab167 | E | G | [ and ] | [J] | 300
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | ----- | ------ C09759 | D | F | ( and ) | G(H | 201 C323a1 | G | D | + and - | E+F | 201 C57a16 | B | A | [ and ] | B[C | 201 C66c43 | B | G | + and - | H+I | 201 Cab167 | D | G | [ and ] | H[I | 201
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | ----- | ------ C09759 | E | F | ( and ) | (((I))) | 3000000 C323a1 | D | D | + and - | +++G--- | 3000000 C57a16 | E | A | [ and ] | [[[D]]] | 3000000 C66c43 | A | G | + and - | +++J--- | 3000000 Cab167 | A | G | [ and ] | [[[J]]] | 3000000
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | --------- | ------ C09759 | F | F | ( and ) | GGG())GGG | 3 C323a1 | E | D | + and - | EEE+--EEE | 3 C57a16 | D | A | [ and ] | BBB[]]BBB | 3 C66c43 | G | G | + and - | HHH+--HHH | 3 Cab167 | G | G | [ and ] | HHH[]]HHH | 3
Class Name | Part | Base Char | Delimiter | Input | Answer ---------- | ---- | --------- | --------- | --------- | ------ Cab167 | B | G | [ and ] | [HI][IH] | 600 C57a16 | F | A | [ and ] | [BC][CB] | 600 C66c43 | F | G | + and - | +HI-+IH- | 600 C323a1 | A | D | + and - | +EF-+FE- | 600 C09759 | G | F | ( and ) | (GH)(HG) | 600
![]() |
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | D | Insert 20 | No rotations 5cb09 | F | Insert 19 | No rotations 5fb4f | F | Insert 19 | No rotations a1a47 | A | Insert 21 | No rotations fa457 | B | Insert 21 | No rotations
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | C | Insert 13 | Rotate about 10, and then rotate about 10. 5cb09 | C | Insert 13 | Rotate about 09, and then rotate about 09. 5fb4f | A | Insert 13 | Rotate about 10, and then rotate about 10. a1a47 | B | Insert 13 | Rotate about 10, and then rotate about 10. fa457 | C | Insert 13 | Rotate about 09, and then rotate about 09.
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | A | Insert 48 | Rotate about 49, and then rotate about 49. 5cb09 | A | Insert 48 | Rotate about 50, and then rotate about 50. 5fb4f | B | Insert 48 | Rotate about 52, and then rotate about 52. a1a47 | F | Insert 48 | Rotate about 50, and then rotate about 50. fa457 | E | Insert 48 | Rotate about 49, and then rotate about 49.
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | F | Delete 80 | No rotation. 5cb09 | D | Delete 80 | No rotation. 5fb4f | E | Delete 79 | No rotation. a1a47 | E | Delete 80 | No rotation. fa457 | F | Delete 82 | No rotation.
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | B | Delete 59 | Rotation about 44. 5cb09 | B | Delete 60 | Rotation about 44. 5fb4f | D | Delete 60 | Rotation about 44. a1a47 | E | Delete 62 | Rotation about 47. fa457 | A | Delete 59 | Rotation about 45.
Hash | Part | Action | Answer ----- | ---- | ----------- | --------------- 38c0c | E | Delete 24 | Rotation about 07, and then rotation about 65. 5cb09 | E | Delete 25 | Rotation about 04, and then rotation about 64. 5fb4f | C | Delete 25 | Rotation about 04, and then rotation about 64. a1a47 | C | Delete 25 | Rotation about 05, and then rotation about 66. fa457 | D | Delete 27 | Rotation about 05, and then rotation about 67.
![]() |
Case 1: If A is an ancestor of B, then A comes before B in the preorder traversal, and after B in the postorder traversal.
Case 2: If A is in the left subtree of the root and B is in the right subtree, then A comes before B in both traversals. Here are the answers going left-to-right, then top to bottom:
1 2 3 4 5 6 7 8 9 10 11 12
- - - - - - - - - -- -- --
Hash 02684: Y N Y Y Y N Y Y Y N Y Y
Hash 106c7: Y Y Y N Y N Y Y Y Y Y N
Hash 5e7fa: Y Y Y N Y Y Y N Y Y Y N
Hash df8e8: Y Y Y Y Y N Y Y Y N Y N
Hash f2595: Y N Y Y Y N Y N Y Y Y Y
![]() |
Hash A B C D E F G H I J K L ----- -- -- -- -- -- -- -- -- -- -- -- -- 606ef 83 67 60 18 21 38 96 3 4 10 8 14 89dde 21 60 22 9 19 23 97 3 4 8 5 14 a0667 26 67 39 18 26 29 48 4 7 13 12 22 e33aa 17 51 81 12 19 44 87 3 4 15 14 21 ee247 45 81 77 9 34 61 69 1 6 10 7 26
![]() |
Case 1: The node has no children (it's a leaf node). You can simply delete it.
Case 2: The node has just one child. To delete the node, replace it with that child.
Case 3: The node has two children. In this case, you find the node in the tree whose value is the greatest value less than (or equal to) the node's value. That will be the rightmost node in the subtree rooted by the left child. That node will not have a right child. First, delete it. Then use it to replace the node that you are deleting. Alternatively, you can replace it with the leftmost node in the tree rooted by the node's right child. Both will work.
![]() |
int height(Node *t)
{
int l, r;
if (t == NULL) return 0;
l = height(t->left);
r = height(t->right);
if (r > l) l = r;
return l+1;
}
|
You needed to use recursion here. Otherwise, your code was convoluted and inevitably incorrect. You lost a point if you did not check to see whether t was NULL.
![]() |
root
/ \
/ \
lc c
/ \
/ \
a b
Set variables for lc and b. Note that b
Node *left_rotate(Node *root)
{
Node *lc, *b;
if (root == NULL) throw ((string) "Error");
if (root->left == NULL) throw ((string) "Error");
lc = root->left;
b = lc->right;
root->left = b;
lc->right = root;
return lc;
}
|
You also needed to check to make sure root->left was not NULL.
A bunch of you put sentinels and parent pointers into your code, which just shows that you're not reading the question carefully.
![]() |