Comp 271-400 Week 3

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.



Recursion

Why is recursive Fibonacci so slow?

See recursion.html

Why does recursive Fibonacci always return a value?




Linked List

Class both.java in linkedlistij.zip: change from ArrayList to LinkedList.

List-related examples:

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.

More complexity

A function is said to be polynomial if it is O(nk) for some fixed k; quadratic growth is a special case.
So far we've been looking mainly at running time. We can also consider space needs.


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

Quicksort implementations

See sorting.html#sorting




in-class lab 2

Install expressionsij.zip.





Trees

binary trees
insertion and search
traversal
tree-based dictionaries