Approximate grading key for Question 4:
Alef (10 points):
There were a number of possible solutions. The classic one is:
- public void add(Comparable data){
- ComparableLink tmp = sentinal;
- while(tmp.next!=null && data.compareTo(tmp.next.data)>0)
- tmp = tmp.next;
- tmp.next = new ComparableLink(data, tmp.next);
- }
In this section, there are three catagories on which your solution was evaluated. These are guidelines to understand your mistakes, and naturally do not include explanations to all possible errors.
Note: Some gradings were not divided into these catagories. More explanations may be given on your answer sheet.
- A 0..+2 : correct handling of the empty list case. Points also taken off if sentinal.data was used (instead of sentinal.next.data), and some other mistakes.
- B 0..+4 : correct loop. Points also taken off if sentinal was advanced instead of a temporary pointer, and some other mistakes. If you called a (nonexistent) add() method of ComparableLink you got 0 out of 4 points, for catagory B.
- C 0..+4 : correct insertion into list; no ruining of the list; creating a new ComparableLink holding "data" (not treating "data" as a link!), and some other issues.
Beit (10 points):
There were a number of possible solutions, recursive and iterative. A recursive solution:
- public boolean isSorted(){
- if (next==null)
- return true;
- if (data.compareTo(next.data)>0)
- return false;
- return next.isSorted();
- }
- A -1/-2 : comparing a ComparableLink instead of a Comparable in compareTo() method.
- B -1 : syntax mistake.
- C -7/-8 : wrong implementation.
- D -1/-2/-3 : logic mistake (light/medium/heavy).
- E -2 : using list methods or fields though inside ComparableLink, like isEmpty(), sentinal.
- F -1 : very inefficient loop (e.g. not using a flag) or recursion (e.g. using & instead of &&).
- G -2 : advancing or using "this" or "next" instead of a temporary pointer ("this" cannot be changed! changing "next" may also ruin the list (see N)).
- H -1 : wrong sort direction: "bigger first", in contrary to question description.
- I -1 : unnecessary ComparableLink creation .
- J -1 : missing/wrong handling of first element after "this" in the list, while handling well the (next==null) case.
- K -2 : missing/wrong handling of (next == null) case.
- L -3 : comparing all elements in the list to list head (this.data), instead of each element's previous.
- M -3 : no/wrong use of compareTo() method
- N -2 : changing (usually ruining) the list data structure.
- O -1 : no/wrong advancement of pointer in the loop