Comp 271-400 Week 3
Cuneo 311, 4:15-8:15
Bailey chapter 5 section 2 on recursion
Bailey chapter 3, on a Vector class
Bailey chapter 6, on sorting.
Bailey chapter 9 section 4 on Singly Linked Lists
Bailey chapter 15, section 4, on Hash Tables.
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.
Why is recursive Fibonacci so slow?
Why does recursive Fibonacci always return a value?
- Postage (currently first-class is 49¢, and post cards are 34¢)
Class both.java in linkedlistij.zip: change from ArrayList to LinkedList.
Table of Factors
This is the example on Bailey page 88. Let us construct a table of all the
k<=n and a list of all the factors (prime or not) of k, and ask how much
space is needed. This turns out to
be n log n. The running time to construct the table varies with how clever
the algorithm is, it can be O(n2) [check all i<k for
divisibility], O(n3/2) [check all i<sqrt(k)], or O(n log n)
[Sieve of Eratosthenes].
Finding a space character in a string
The running time depends on whether we're concerned with the worst case or
the average case (we are almost never interested in the best case). If the
average case, then the answer typically depends on the probability
distribution of the data. If the text consists of English words separated by
spaces, then in most cases we'll find a space in <=10 steps, as most
English words are <= 10 characters long.
A function is said to be polynomial
if it is O(nk) for some fixed k; quadratic growth is a special
So far we've been looking mainly at running
time. We can also consider space needs.
in-class lab: GetHashCode() values of strings from hashij.zip's
classes hashCodes.java and hashStats.java.
Chapter 6: Sorting
in-class lab 2
insertion and search