Comp 388-005 Week 3

Lewis Tower 415, 4:15-8:15

Welcome

Readings:

 


Recursion


    so far we've done gcd()
Go through these examples in recursion.html.

in-class lab 1

    Answer-cache implementation of Fibonacci(n):

    public static long rfibonacci(int N) {
        if (N<=1) return 1;
        if rfibonacci(N) is in the answer cache, return answer_cache[N]
        return rfibonacci1(N-2) + rfibonacci1(N-1);        // but put result into answer_cache[N] first
    }

in-class lab 2

    Get expr_assign.cs (with oneline_tokenizer.cs) to run
Both files together are in expr_assign_all.cs


Quicksort

    sorting.html#quicksort



Hashing: lists.html#hashing

   in-class lab: GetHashCode() values of strings in lab1




Linked List

See lists.html#linked.

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

Space in a string

The answer 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.

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.