Comp 388-005 Week 4
Lewis Tower 415, 4:15-8:15
Welcome
Readings:
Quicksort
sorting.html#quicksort
More on pivoting?
Object sorting
Hashing
lists.html#hashing
Array-list buckets vs Linked-list buckets
Hash-based dictionary implementation (hashdict.cs)
Open hashing
in-class lab: GetHashCode() values of strings in lab1, or in
hashcodes.cs
https://referencesource.microsoft.com/#mscorlib/system/string.cs,0a17bbac4851d0d4,references
Binary trees
http://pld.cs.luc.edu/courses/388/mnotes/trees.html
demo programs: inttree.cs,
In-class lab:
- get intraverse() to print in the other order, so that, turned on its
side, the output looks like a tree
- Try some random data-insertion orders.
Some ways to traverse a tree: traversers.cs
- traversal
- building
- ordered
- binary search trees
- versus hash tables
- recursive operations
- sum
- max
- depth
- search
- insert
Study guide
Parse trees again
Add a new level: factor -> efactor [ '^' efactor]
efactor -> ident | number | '(' expr ')'
List-related examples:
space complexity: see lists.html#space,
the Table of Factors example.
List expand() and time-v-space tradeoffs
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.