### Comp 271-400 Week 3

Crown 103, 4:15-8:15

Welcome

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

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

#### 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.

### Hashing

Hashing: lists.html#hashing

in-class lab: GetHashCode() values of strings from hashij.zip's classes hashCodes.java and hashStats.java.

### Chapter 6: Sorting

See sorting.html#sorting

quicksort

### Recursion

Recursion starts at Bailey page 94
See recursion.html

Go through factorial in detail

Fibonacci

• Why is recursive Fibonacci so slow?
• Why does recursive Fibonacci always return a value?
Induction
Postage (currently first-class is 49¢, and post cards are 34¢)
Expressions.

in-class lab 2

Install expressionsij.zip.

Trees

binary trees
insertion and search
traversal
tree-based dictionaries