Algorithm Analysis (CSC 301 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Outline] [EBoard] [Reading] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Algorist]
Related Courses: [Walker (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Overview
SetOfStrings Implementations
SetOfStrings ADT provides
add(set,val), remove(set,val), contains(set,val)union(set,set), subtract(set,set)SetofStrings.
(You need not write code; just describe memory arrangement and
related issues.)With a good hash function, set is expected O(1); worst case is O(n), where n is the number of slots in the hash table.
Assumption one: Hash function distributes things appropriately. For any input, there are equal odds that it goes in any of the n slots.
Assumption two: There are no more than n/2 values in the hash table. (Alternately: n values in the hash table, at least 2n slots in the hash table.)
Assumption three: Probed hash table.
First time we look in the hash table: 50% we find an empty slot
Average number of steps
1*n/2 + 2*n/4 + 3*n/8 + 4*n/16 + 5*n/32 + ...
Average = ^/n
1*1/2 + 2/4 + 3/8 + 4/16 + 5/32 + ...
Sum from k = 1 to infinity of k/2^k
1/2 + 1/2 + 3/8 + 4/16 + 5/32 + ...
1 + 3/8 + 4/16 + 5/32 + ...
1 + 10/16 + 5/32 + ...
1 + 25/32 + 6/64 + ...
1 + 56/64 + 7/128
1 + 119/128 + 8/256
1 + (2^k-(k+2))/2^k
Never reaches 2, although gets arbitrarily close
The stuff before the ellipses 1 + 56/64 + 7/128...
I have a string, big, of length n. I have another string, small, of length k < n. Does small appear as a substring of big?
What's your strategy?
What's a really bad input for your strategy?
Strategy O
Strategy H
With the cool Skiena hash function, what do we know about
hash(substring(str, 0, k)) vs hash(substring(str, 1, k+1))
We found a cool formula
hash(substring(str, 1, k+1) =
(hash(substring(str, 0, k) - str[0]*alpha^k )* alpha + str[k+1]
So we can compute the n different hash codes in O(n + k) time = O(n) time
But ... we have to use a hash table. And if we have to create a hash table, We're using a lot of extra space! (Probably O(n) space.)
There's often a time/space tradeoff in your algorithms
A tree is "a graph with no cycles"
A tree is "a collection of values such that with a hierarchial relationship"
Each value may have one or more children (child values) and at most one parent value. The relationship is symmetric relationship: if a is a child of b, then b is a parent of a.
Goal for Monday: Work on terminology and notation; Think about traversal; Think about balancing techniques