# Middle exam rubric

## Problem 1

 Initialize `Deque` 2 For loop control 3 Push 1 Return 1

## Problem 2 — 1.3 points each part

 Appropriate instance or class 0.7 Method name 0.2 Argument 1 0.2 Argument 2 0.2

## Problem 3 — 2/3 point each stack

```       3       2   2
5   5   5   5   5   5
```

## Problem 4

Insertion and selection sort are 1.5 points each. When half-way through a insertion sort, the elements in the bottom half should be sorted and the elements in the top half should be unchanged. When half-way through a selection sort, the bottom half should contain all the smallest elements correctly sorted.

Quicksort is 1 point. The elements will be partioned by the pivot.

Grading will be a little subjective. Here are some plausible arrangments.

```  insertion      181   255   344   431   107   446   331   182
selection      107   181   182   255   344   446   331   431
quicksort      182   181   255   107   331   446   431   344
```

## Problem 5 — 1 point each part

 Value 0.7 Type 0.3

## Problem 6

There are 23 tokens. All count equally in dividing the 3 points.

• `int`
• `z`
• `=`
• `x`
• `.`
• `toString`
• `(`
• `)`
• `+`
• `"DOG"`
• `+`
• `(`
• `int`
• `)`
• `Math`
• `.`
• `PI`
• `+`
• `v`
• `[`
• `0`
• `]`
• `;`

There are 14 subexpressions. All count equally in dividing the 3 points.

```x + y * ( z + 5 ) > 13 && a <= 0
x + y * ( z + 5 ) > 13
x + y * ( z + 5 )
x
y * ( z + 5 )
y
( z + 5 )
z + 5
z
5
13
a <= 0
a
0
```
• `"CAT"`
• `3.5`
• `"CAT" + 3.5`
• `x`
• `(int) x`
• `"CAT" + 3.5 + (int) x`
• ## Problem 7

1 point for each of the first five, 1.5 points for each of the next two, 2 points for the last one.

## Problem 8

 if-else 2 return 0 1 return recursive call 3

## Problem 9

 counter — initailize and increment 2 `k` — initailize and double 2 loop termination 2 return 1

## Problem 10

Like 8, if recursive.

```def logOf2(n):
if (n <= 1):
return 0
else:
return 1 + logOf2(n/2)
```

## Problem 11

 `public class ComparableDieextends Dieimplements Comparable` 2 `public int compareTo(Die d)` 2 `retrun getValue() - d.getValue` 2

## Problem 12

In parts A to H, points generally distributed over the number of significant syntax items in the subproblem.

### Problem 12I

 Testing if size is even 1 Computing median if even size 2 Computing median if odd size 1

In the even case, if sum is divided by 2 rather that 2.0, 0.4 points are deducted. If the indexes used to access the array elements are one too high (`cNumbers[cNumbers.length/2+1]` rather than `cNumbers[cNumbers.length/2]`), 0.3 points is deducted each time. If `cNumbers.length()` is used rather than `cNumbers.length`, 0.3 points is deducted.

### Problem 12J

One point for the various significant actions.

• Call of `readNumbers`
• Action if result was `null`
• Call of `getMedian`
• `for` loop through array
• Test if array element is negative
• Printing array element