You are probably being recorded (and transcribed)
Approximate overview
If you’d like to suggest token events, please let me know in advance of class.
String.substring(lb, ub). You see it in Random.nextInt(lb, ub).x and y tell us very
little, particularly when we’re not dealing with coordinates.It would be nice to see more of you decompose. Decomposed code is much easier to read.
for (int i = 1; i < values.length; i++) {
insert(values, i);
} // java
vs.
for (int i = 1; i < values.length; i++) {
int j = i - 1;
while (j >= 0) {
...
T tmp = values[j];
values[j] = values[j-1];
values[j-1] = tmp;
break;
} // while
} // for
On that note: break is ugly and should be used sparingly.
while ((j >= 0) && (order.compare(a[j], value) >= 0))Your insert loop should also stop as soon as you find the right place. Otherwise, you guarantee that it’s O(n^2), even when the array is already sorted.
Some of you wrote about “sorted half” and “unsorted half”. I’d say that “half” is a bad term. How about “portion”? (More generally, be careful about the terms you use.)
It would be nice to see more of you decompose. An indexOfSmallest
procedure would clarify code.
for (int i = 0; i < vals.length; i++) {
swap(vals, i, indexOfSmallest(vals, i));
} // for
For some reason I don’t quite understand, some of you did the recursion within your partition/DNF procedure. But we want to separate partitioning/DNFing from the recursive sorting. Why? It turns out we can use partition/DNF for other tasks, too.
Quicksort (even the partition-based Quicksort) relies on us splitting the array into three parts, one of which is the pivot (or the pivot plus equal values). Why? Because we need to ensure that we recurse on smaller arrays.
Please don’t say “Quicksort is an O(nlogn) sorting algorithm.” It’s not. You could say “Quicksort is expected O(nlogn)” or something like that, but we could repeatedly choose bad pivots and make it an O(n^2) sorting algorithm.
Copying arrays and subarrays is slow. Try to do as little as possible.
Some of you computed the midpoint with lb/2 + ub/2. That doesn’t
give the midpoint if both values are odd.
lb is 3 and ub is 3, 3/2 = 1, so we compute 2.lb is 3 and ub is 5, 3/2 = 1, 5/2 = 2, so we compute 3
(rather than 4).(lb + ub) / 2 is more correct, but potentially dangerous if the
lb and ub are qire large (overflow).lb + (ub - lb) / 2.lb / 2 + ub / 2 + (lb % 2 + ub % 2) / 2.Updates coming soon (including tests).
Demo coming on Tuesday (sorry for the delay).
Can we get rid of the hidden field thing in mvn checkstyle:check?
Yes.
SoLA 11 will open tonight, right? And it’s optional?
Yes and yes.
MP5?
Graders had as much trouble as you did. Hopefully soon.
Two labs today, one on chained hash tables and one on probed. Do them in either order. They use the same repository.
Make sure the repo ends in -maven.
== to compare keys. Use .equals.find, the first place you should look is the hash of
the key.
clear method.For probed hash tables, are we really any better off using a probe offset of 17 than 1?
If we worry about clustering, using larger probe offsets helps us avoid collisions.