CS 2401, Fall 2009
 
Typical mistakes for Test 2

Problem 1/2:

* the assignment was NOT to guess why the code is incorrect by looking at it, 
but to TRACE its execution; for that, you need an example

* the "corrected" code is sometimes still wrong, you should have traced it to 
make sure that it is correct

Problem 3:

* in a linked list implementation of the stack, the top element is always first, 
not last

* we ask about a linked list implementation, NOT about an array implementation

* we push an element 1, NOT a node; push is an abstract ADT operation, it should 
be used the same way whether we have a linked list or an array implementation

* to trace a code, you need to have some code to trace

Problem 4-5:

* wrong transformation into postfix

* wrong algorithm for computing the postfix expression

* with pop(), you are also need to peek(); if you only pop, you lose the values

* when you need two values, you need to first peek and pop, then again peek and 
pop if you peek twice in a row, you get the two copies of the same top value 
from the stack

* after you perform an operation, you need to push the result back into the stack

Problem 6:

* explaining the general role of instance variables instead of the role of this 
specific instance variable

* false claim that without, say, count or last, we will not be able to find the 
number of elements in a linked list or the last element of the linked list; in 
reality, we can do that -- but we will need a time-consuming traverse 
(while loop)

Problem 7:

* forgetting to indicate which element is first and which is last; in the
array implementation of a queue, this is necessary

* deleting the wrong element; in the queue, it is first in, first out, so if 3 
was placed, then the deleted element is 3

* moving all the elements when one of them is deleted; there is no need to move 
the elements in a queue

Problem 8:

* not inserting the front element 2 in the second command

* confusion between insertFirst and insertLast