Comp 271-400 Week 4

Cuneo 311, 4:15-8:15

Welcome

Readings:

    Bailey chapter 5 section 2 on recursion
    Bailey chapter 6, on sorting.
    Bailey chapter 9 section 4 on Singly Linked Lists
    Bailey chapter 15, section 4, on Hash Tables.

    Bailey chapter 3, on a Vector class

    Morin 3.1: Singly Linked Lists
    Morin 5.1: Chained Hash Table
    Morin Chapter 11: sorting (Merge-sort and Quicksort only)

Primary text: Bailey, online, and maybe Morin, also online.


Exam next week

We will start the exam around 6:20. You'll have (almost) two hours, but you shouldn't need all that time.

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 mergesort be faster if the data is already sorted? The algorithm executes exactly the same steps!
Demo: pldsorting/DualMerge.java, prev/sortspeed

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



Radix Sort

    133    312    121    213    122    211    321    132   223    332

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)




in-class lab 1

Install expressionsij.zip.





Trees

binary trees
insertion and search
traversal

tree-based dictionaries

    Lab 4


Recursion

Recursion starts at Bailey page 94
See recursion.html and recursion1ij.zip.