CS140 Midterm 2 Grading Guide
Written Exam
- (12 points)
- 2 points each for parts a and b.
- 4 points each for
parts c and d.
- For parts a and b deduct 1 point for
having extraneous constants or terms (e.g., O(5n2) or
O(n + n2).
- For part c the answer should include some reference to the fact
that T(50) for Algorithm 1 is around 12000-13000 and that T(50) for
Algorithm 2 is above 50000. If they just say that the constants
dominate the computation, that should get 2/4 points. They need to
"prove" that the constants dominate the computation by computing
T(50) for each of the two algorithms. If the student answers that
Algorithm 2 is better because its Big-O running time is less,
than there should be no credit for part c.
- For part d the reason must reference the Big-O
notations computed in parts a and b. Deduct 1 point for not referring to
the Big-O running times (they don't have to explicitly say Big-O, but they
must indicate what the Big-O running times were). If they mis-compute the
Big-O running times for Algorithms 1 and 2 and their miscomputation has
Algorithm 1 being faster than Algorithm 2, then give them full credit
in part d if they say Algorithm 1 is faster than Algorithm 2.
- (14 points) 2 points for each question
- (2 points) (a) 0 for anything else
- (2 points) (h) 1 point for e (set), 0 for anything else
- (2 points) (c) 1 point for b (list), 0 for anything else
- (2 points) (f) 0 points for anything else
else
- (2 points) (a) 1 point for either b (list) or c(deque), 0 for anything else
- (2 points) (b) 0 points for anything else
- (2 points) (d) 0 points for anything else
- (10 points) 1 point for each answer
- (6 points)
- 2 points, all or nothing for dangling pointer
- 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.
- (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.
- (10 points)
- 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.
- 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.
- (12 points)
- (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 points) all or nothing for statement 5 being
the seg faulting statement
- (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
- ( 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.
- (10 points): 1 point each for:
- 4 points: The 4 list nodes pointing to the correct Person objects
- 1 point: The lastPerson pointer pointing to winnie
- 1 point: The newPerson pointer pointing to winnie
- 4 points: The 4 bestFriend pointers pointing to the correct Person
objects (mickey's bestFriend pointer should be NULL)
Use your judgement to deduct points if things are incorrectly
drawn, such as missing sentinel nodes, Person objects being
mis-drawn, etc.
Coding Exam
- Codes
- -3: forgot to pass the lists by reference, thus not allowing the
original codes list to be modified.
- -1: uninformative variable names
- -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.
- -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)
- -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.
- -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.
- -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.
- -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.
- various: code that is hard to understand or incorrect
- -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.
- -1: failing to pass the used codes list by reference, thus forcing
a copy of the list to be made, which is inefficient.
- -10: skipping used codes
- various: incorrectly advancing either the used codes or outstanding
codes iterators
- Clubs
- adding a club to the hash table (20 points)
- -10: locates the club using a linear search through the entire
hash table rather than just the bucket that could potentially
contain the club
- -10: does not properly
use a linear search through the bucket to which
the club hashes in order to locate the club
- -4: does not properly create a new club and add it to the bucket
- -1: searches to the end of the bucket even after finding the
club--this is inefficient.
- -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.
- -3: does not properly add a student to a club's member set
- -3: does not correctly determine if the club already exists
- adding new students and adding students to clubs
- -2: does not skip a student if an attempt is made to add
a non-existent student to a club
- -3: does not properly read input from stdin or else properly
extract input from a stringbuffer if getline is used
- -2: calling find twice, rather than just once, when
determining whether to add a student to a club in the "JoinClub"
command
- -4: does not correctly determine if the student exists before
adding the student to the club
- -4: does not correctly insert a student into the club map
- -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.
- -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
- -4: does not correctly create a new person object for a new
student
- -4: does not correctlyl insert a new student into the students
map
- overall organization
- -1: uninformative variable names
- -1: does not use an "else" in mutually exclusive cases
(e.g., "AddStudent"/"JoinClub")