Review:
- Dictionaries
for ordered sets
- Binary
tree.
- Tree
balancing by rotations
- drawbacks
in geometry: rebuild on rotation
Returning to average case:
- Assign
random ``arrival orders'' to keys
- Build
tree as if arrived in that order
- Average
case applies
- No
rotations on searches
Choosing priorities
- define
arrival by random priorities
- assume
continuous distribution, fix.
- eg,
use 2 log n bits, w.h.p. no collisions
Treaps.
- tree
has keys in heap order of priorities
- unique
tree given priorities--follows from insertion order
- implement
insert/delete etc.
- rotations
to maintain heap property
Depth d (x) analysis
- Tree
is trace of a quicksort
- We
proved O(log n) w.h.p.
- for x rank k, E[d (x)] = Hk + Hn - k + 1
- 1
- S- = {y
S | y
x}
- Qx = ancestors
of x
- Show E[Q-x] = Hk.
- to
show: y
Qx-
iff inserted before all z, y < z
x.
- deduce:
item j away has prob 1/j.
Add.
- Suppose
y
Qx-.
- The
inserted before x
- Suppose
some z between inserted before y
- Then
y in left subtree of z,
x in right, so not ancestor
- Thus,
y before every z
- Suppose
y first
- then
x follows y
on all comparisons (no z splits
- So
ends up in subtree of y
Rotation analysis
- Insert/Delete
time
- define
spines
- equal
left spine of right sub plus right spine of left sub
- proof:
when rotate up, on spine increments, other stays fixed.
- Rx length of
right spine of left subtree
- E[Rx] = 1 - 1/k if rank k
- To
show: y
Rx
iff
- inserted
after x
- all z, y < z < x,
arrive after y.
- if z before y, then y goes left, so not on spine
- deduce:
if r elts between, r! of (r
+ 2)! permutations work.
- So
probability 1/r2.
- Expectation
1/(1 . 2) + 1/(2 . 3)
+ ... = 1 - 1/k
- subtle:
do analysis only on elements inserted in real-time before x, but now assume they arrive in random order in
virtual priorities.
- ruler
intuition
- achieve
with geometric variables
- backwards
analysis of search path
- insert/delete
time
classical shortest paths.
- dijkstra's
algorithm
- floyd's
algorithm. similarity to matrix multiplication
Matrices
- length
2 paths by squaring
- matrix
multiplication. strassen.
- shortest
paths by ``funny multiplication.''
- huge
integer implementation
- base-(n + 1) integers
Boolean matrix multiplication
- easy.
- gives
objects at distance 2.
- gives
n-mul algorithm for problem
- what
about recursive?
- well
can get to within 2: let Tk
be boolean ``distance less than or equal to 2k.
Squaring gives Tk + 1.
- what
about exact?
Seidel's distance algorithm.
- log-size
integers:
- parities
suffice:
- square
G to get adjacency A',
distance D'
- if
Dij
even then Dij = 2D'ij
- if
Dij
odd then Dij = 2D'ij - 1
- For
neighbors i, k,
- Dij - 1
Dkj
Dij
+ 1
- exists
k, Dkj = Dij - 1
- Parities
- If
Dij
even, then D'kj
D'ij
for every neighbor k
- If
Dij
odd, then D'kj
D'ij
for every neighbor k, and strict for at
least one
- Add
- Dij even iff
Sij =
D'kj
Dijd (i)
- Dij odd iff
D'kj < Dijd (i)
- How
determine? find S = AD'
To find paths: Witness product.
- easy
case: unique witness
- multiply
column c by c.
- read
off witness identity
- reduction
to easy case:
- suppose
r columns have witness, where 2k
r
2k
+ 1
- choose
each column with probability 2-k.
- prob.
exactly one witness: r . 2-k(1
- 2-k)r - 1
(1/2)(1/e2)
Mod 3:
- Recall
some neighbor distance down by one
- so
compute distances mod 3.
- suppose
Dij = 1 mod 3
- then
look for k neighbor of i
such that Dkj = 0 mod 3
- let
Dij(s)
= 1 iff Dij = s mod 3
- than
AD(s)
has ij = 1 iff a
neighbor k of i
has Dkj(s)
- so,
witness matrix mul!