march 5
6.1
Searching a list by presorting it.
do 6.1 #6 in class.
6.3
balanced search trees
The basic notion is that we keep our information
organized in a binary tree so that we can find
things in it quickly, with a binary search.
The price we pay is more complexity in adding
and deleting elements, which requires "rotating"
various parts of the tree to keep it balanced.
If it doesn't remain balanced, then we're left
with the possibility of trees that extend down
in only one direction ... and then searching
for something turns into sequential search.
Note the differences between these and heaps: heaps place keys in a different order (bigger than children), and have all levels but last full. Heaps are *not* designed to optimize searching.
Do 6.3 #1 in class. (Careful: all nodes are binary ... even if both links aren't shown.)
6.4
heaps and heapsort
A heap is a binary tree with
- "keys" (a value of some sort) in each node
- all levels are full except
- bottom one can have empty places
- missing ones always on the right
- parent value must be bigger than children values
Definition: a "heap" is a binary complete (except for bottom which may have some right nodes missing) tree with parent key's > children's.
- can be stored in a linear array
- O(log n) or better perfomance for a variety of operations (see wikipedia table)
- construction
- insert
- delete (given, max, or min)
- find min, max, k'th
- merge
Do 6.4 #1 in class.
6.5
Finding a**n mod m efficiently:
- express n in binary
- starting with 1 repeatedly
- square, add to sum if 1 in binary representation of n
Do an example on the board.
6.6
reduction
Example on pg 244 : river-crossing problem as a graph-search problem (state-space)
"AI is the branch of computer science in whcih state-space graphs are a principle subject."