CS140 Midterm 2 Grading Guide


Written Exam

  1. (12 points)
  2. (14 points) 2 points for each question
    1. (2 points) (a) 0 for anything else
    2. (2 points) (h) 1 point for e (set), 0 for anything else
    3. (2 points) (c) 1 point for b (list), 0 for anything else
    4. (2 points) (f) 0 points for anything else else
    5. (2 points) (a) 1 point for either b (list) or c(deque), 0 for anything else
    6. (2 points) (b) 0 points for anything else
    7. (2 points) (d) 0 points for anything else

  3. (10 points) 1 point for each answer

  4. (6 points)
    1. 2 points, all or nothing for dangling pointer
    2. 4 points, the important point they need to make is that the dangling pointer, name2, has overwritten the memory pointed to by p and hence the call to p->sourceFile->open is likely to seg fault. Use your judgement to award partial credit.

  5. (8 points) 1 point for each answer. If the student answered by giving the times for an individual operation (e.g., O(log n) for a map's find/insert rather than O(n log n)) then award half credit.
  6. (10 points)
    1. 5 points for identifying the copy of the firstnames set as being the source of the inefficiency. Anything else should probably get 0 points unless you see a compelling reason to award partial credit.
    2. 5 points for using either of the two techniques in the answer key to correct the inefficiency. Also award full credit if the student uses another technique to eliminate the copy that works correctly. It's going to be hard to award partial credit if the student missed part a.

  7. (12 points)
    1. (5 points for the diagram. One point each for currentNode, nextNode, Nancy->prev, Nancy->next, and Sarah->prev having the correct values. Deduct one point for any other pointer that is incorrect but don't deduct more than 5 points total.
    2. (2 points) all or nothing for statement 5 being the seg faulting statement
    3. (2 points) for being able to properly describe what the seg faulting statement is doing. If the student chooses a statement other than statement 5 as the seg faulting statement, then give the student full credit for correctly stating what that statement is trying to do. Here is what each statement is trying to do:

      • statement 1: Make nextNode point to Sarah's node
      • statement 2: Make Nancy's prev pointer point to Ben's predecessor node, or NULL (both answers are acceptable).
      • statement 3: Make Nancy's next pointer point to Ben's node
      • statement 4: Make Sarah's prev pointer point to Ben's node
      • statement 6: Make Ben's next pointer point to Sarah's node
    4. ( 3 points): You will need to use your judgement in awarding partial credit. You should deduct 1-2 points if you find the code really difficult to read.
  8. (10 points): 1 point each for: Use your judgement to deduct points if things are incorrectly drawn, such as missing sentinel nodes, Person objects being mis-drawn, etc.

Coding Exam

  1. Codes
    1. -3: forgot to pass the lists by reference, thus not allowing the original codes list to be modified.
    2. -1: uninformative variable names
    3. -5: making multiple passes through the codes list, resulting in an O(n2) algorithm, rather than a single pass through the codes list, which results in an O(n) algorithm.
    4. -3: comparing the used codes and outstanding codes iterators for equality rather than comparing their de-referenced contents. If the used codes iterator is named used_iter and the outstanding codes iter is named outstanding_iter, then the comparison must be (*used_iter == *outstanding_iter), not (user_iter == outstanding_iter)
    5. -1: the function should return when the used codes list is exhausted. Since the used codes list is a subset of the outstanding codes list, it is guaranteed that the used codes list will be exhausted either before or at the same time as the outstanding codes list.
    6. -1: using conditions that are guaranteed to be either true or false, and hence are a waste of the CPU's time. If your code has multiple such conditions, you will lose multiple points.
    7. -1: if you start at the beginning of the outstanding codes list each time you advance to the next used code, then you should stop traversing the outstanding codes list as soon as you find the code to delete. It makes no sense to continue traversing the outstanding codes list after that point because another match cannot occur.
    8. -1: failing to use the return value from the list erase() function. The return value is an iter to the list node immediately after the erased node. There is no need to allocate a temporary variable that holds a pointer to the next node in the list and then assign this temporary variable back to the iterator traversing the outstanding codes list. Simply set the iterator traversing the outstanding codes list to the return value of the erase function.
    9. various: code that is hard to understand or incorrect
    10. -5: incrementing, decrementing, or testing an iterator after the node it points to has been erased. These are undefined operations because the iterator no longer points at anything.
    11. -1: failing to pass the used codes list by reference, thus forcing a copy of the list to be made, which is inefficient.
    12. -10: skipping used codes
    13. various: incorrectly advancing either the used codes or outstanding codes iterators
  2. Clubs
    1. adding a club to the hash table (20 points)
      1. -10: locates the club using a linear search through the entire hash table rather than just the bucket that could potentially contain the club
      2. -10: does not properly use a linear search through the bucket to which the club hashes in order to locate the club
      3. -4: does not properly create a new club and add it to the bucket
      4. -1: searches to the end of the bucket even after finding the club--this is inefficient.
      5. -2: searches the bucket twice--once to determine if the club is in the bucket and a second time to determine the club's index in the bucket. Once you find the club the first time, save the index so you do not need to do a second search.
      6. -3: does not properly add a student to a club's member set
      7. -3: does not correctly determine if the club already exists
    2. adding new students and adding students to clubs
      1. -2: does not skip a student if an attempt is made to add a non-existent student to a club
      2. -3: does not properly read input from stdin or else properly extract input from a stringbuffer if getline is used
      3. -2: calling find twice, rather than just once, when determining whether to add a student to a club in the "JoinClub" command
      4. -4: does not correctly determine if the student exists before adding the student to the club
      5. -4: does not correctly insert a student into the club map
      6. -4: using while(cin), while(!cin.eof()), or while (!cin.fail()) rather than the while (cin >> ...) idiom we have taught you. Using either of the first two idioms causes your loop to execute 1 too many times.
      7. -4: does an O(n) linear search through the student map to find a student rather than using the map's O(log n) find method
      8. -4: does not correctly create a new person object for a new student
      9. -4: does not correctlyl insert a new student into the students map
    3. overall organization
      1. -1: uninformative variable names
      2. -1: does not use an "else" in mutually exclusive cases (e.g., "AddStudent"/"JoinClub")