1. (10 points): BSTree deletion: You will need to use your judgment in grading this problem. Below are some guidelines on how to assign points. You should also make minor deductions if they have modified other parts of the tree that shouldn't be modified.

    1. (6 points): 170 replaces 200

    2. (4 points): 160 promoted to become the right child of 150

    If they try to delete from the right subtree instead, then they get 5 points of partial credits follows:

    1. (3 points): 325 replaces 200

    2. (2 points): 375 stays as 325's right child

  2. (8 points) Rotation: You will need to use your judgment in grading this problem. Below are some guidelines on how to assign points. You should also make minor deductions if they have modified other parts of the tree that shouldn't be modified.

    1. (3 points) 175 becomes the left subtree of 250

    2. (3 points) 250 becomes the left child of 300

    3. (2 points) 200 becomes the right child of 175

  3. (12 points): AVL trees: You will need to use your judgment in grading this problem. Below are some guidelines on how to assign points. You should also make minor deductions if they have modified other parts of the tree that shouldn't be modified.
    1. Identify the bottom-most node that violates the AVL condition and explain why that node violates the AVL condition.

      1. _________ (2 points): identifies 200 as the node that violates the AVL condition

      2. _________ (2 points): uses a height calculation to show that the height of 150 is 2 and the height of 400 is 0, and hence that the two children's height differs by 2. It is not enough for the answer to say that the height of 200's two children differs by 2.

    2. In order to rebalance the tree do we have to use the zig-zig case or the zig-zag case? Justify your answer.
      1. (2 points): Answer is zig-zag

      2. (1 points): Good, well-reasoned justification
    3. Use the proper rotation(s) to rebalance the above tree so that it becomes a legitimate AVL tree.

      1. (2 points): 175 becomes the right child of 100

      2. (1 points): 150 becomes the left child of 175

      3. (1 points): 200 becomes the right child of 175

      4. (1 points): 160 becomes the right child of 150

    If the student incorrectly said that the first invalid node is the root of the tree, which is 100, then the following answers become correct for parts b and c and the student should receive full credit if they answered as follows:

  4. (10 points): Give 0 points for a C++ implementation. That's not what I want to see here. I told the students during the exam that I want a mathematical definition of gcd.
    1. (4 points): base case correctly stated
    2. (6 points): recursive case correctly stated: the answer must handle both the case where a < b and a > b. Deduct 1 point if the recursive case has a ≤ b or a ≥ b since equality is the base case, not the recursive case.

  5. (8 points) 2 points each, all or nothing

  6. (12 points) 2 points for each subpart, all or nothing. The one exception is (f) where you should give 1 point for saying a vector.

  7. (10 points): BTrees-You're going to have to use your judgment on this problem. Below are some rough guidelines on how to assign points. You should also make minor deductions if they have modified other parts of the tree that shouldn't be modified.

    1. (3 points) 550/600 are in one leaf node and 700/750 are in a second leaf node
    2. (3 points) The interior node that contained 300, 500, 800, and 1000 in the original BTree now consists of two interior nodes, with 300/500 in one node and 800/1000 in the other node.
    3. (2 points) 650 has been promoted all the way to the root of the tree and the root now has the two keys 200/650.
    4. (2 points) All interior nodes point to the correct children.

  8. (15 points) Roughly speaking the points should be allocated as follows:
    1. (2 points) Correctly creates and initializes a new DNode with the value.
    2. (1 point) Correctly returns a pointer to the new node
    3. (3 points each) Correctly links the new node into the doubly linked list. In the following "node" refers to the parameter named "node" that was passed to InsertBefore and "previous node" means "node's" previous node before the insertion occurred.
      1. Makes the new node's forward link (flink) point to node
      2. Makes the new node's backward link (blink) point to node's previous node
      3. Makes the previous node's forward link (flink) point to the new node
      4. Makes the node's backward link (blink) point to the new node
    4. (Deduct 3 points for an incorrect order of operations) If the student saved a pointer to the previous node before trying to link in the new node, then the order of the operations does not matter. However, be on the lookout for code which prematurely change's node's blink pointer, thus wiping out the pointer to the node's predecessor node:
      	  node->blink = new_node;
      	  node->blink->flink = new_node;  
      

      The problem with the second statement in the above code is that it is trying to set the node's predecessor to point to new_node. However, the first statement wiped out the pointer to the node's predecessor node, so the second statement is actually making new_node's flink point to new_node. Similarly the following code is problematic:

          node->blink = new_node;
          new_node->blink = node->blink;
        
      The second statement is trying to make new_node's blink point to node's predecessor node but the first statement wiped out the pointer to this predecessor node. As a result the second statement is actually making new_node point back to itself.

Coding Problems

  1. Final Recursion (BinSearch)
    1. ( 2 points) Need to check the base case for key not found before checking the base case for key found to prevent index out of bounds issues.
    2. ( 4 points) Correctly writes the base case for key not found
    3. ( 4 points) Correctly writes the base case for key found
    4. ( 2 points)Middle computed correctly
    5. ( 5 points) Correctly determines if the key is in the upper or lower half of the vector.
    6. (8 points) Correctly compute the dimensions of the upper or lower half of array for the recursive call
    7. ( 5 points) The recursive calls to binsearch are properly done, other than the computation of dimensions
  2. Expression Tree
    1. (10 points) Correctly writes the base case for a leaf
    2. (10 points) Correctly writes the recursive calls to evaluate for the left and right children
    3. (10 points) Correctly uses the operation variable to compute the correct result and return it.