Welcome

Bailey chapter 12 on binary trees, especially sections
3, 4 and 6

Bailey chapter 14 on binary search trees, sections 1-4

Morin chapter 6 on binary trees, sections 1 and 2

It will probably be **online**, on sakai. Stay tuned!

The study guide is on Sakai. Answers will be posted at the end of this week.

You can bring up to **three pages** (sides) of your own **printed**
or handwritten notes. You will also receive a copy of StrList.java, which
includes examples of basic Java constructions.

There's an algorithmic reason why quicksort's speed is affected by whether the data is already sorted: if we pick data[left] as the pivot in a sorted array, we'll partition into an empty left half and a right half of size N-1.

But why should

Demo: pldsorting/DualMerge.java, prev/sortspeed

Related question: why is insertion sort faster than selection sort?

How fast *is* quicksort? If you divide an interval in half, at
random, what is the expected value of the smaller and larger parts?

Naive approach: bucketize on the first digit, then sort the buckets recursively.

1337 approach: bucketize on the last digit, concatenate, bucketize on second-to-last digit, concatenate, bucketize on the first digit (third-to-last digit)

Trees

binary trees

binary *search* trees

insertion and search

traversal

tree-based dictionaries

See recursion.html and recursion1ij.zip.

- Expressions
- Assignment
- Framework: parsing statements plus
*syntax-directed actions*. - Exponentiation?

**in-class lab 1**

Install expressionsij.zip
and implement exponentiation

New grammar:

/* Grammar:

expr ::= term { addop term }

term ::= efactor { mulop efactor }

efactor ::= factor [ '^' factor ]

factor ::= number | '(' expr ')'

/* */

Changes: modify termeval() so as to call efactorEval(); add efactorEval():

result = factoreval();

if (t.equals(theToken, "^") {

theToken = t.token();

long res2 =
factorEval();

result =
power(result, res2);

}

private long power(long num, long exp)
{ // this is actually C#. Can you tell?

long prod = 1;

for (int i=0; i<exp; i++) prod *=
num;

return prod;

}