day 11 2/16/98 ``Shouldn't ask questions that you don't want to know the answer.''
The cost of a search for ai is equal to Depth(ai)+1 if the search is succesful, otherwise the cost is Depth(newleaf) .
Expected cost = åipi(D(ai)+1)+åiqiD(i)
Tij = min cost tree {ai+1,...,aj} , 1 £ i < j £ n
Suppose we want to compute Tij and all subintervals have been calculated. Pick a key ak:i+1 £ k £ j . Lookup the cost of Tik-1 and Tkj .
|
|
Then,
|
This is formula involves exponential computation without memoization. With memoization it is O(n3) because there are O(n2) cij and each cij costs O(n) to calculate.
The code {10,0,01} is not uniquely decipherable. 010 can be parsed as: 0(10) and as (01)0 . An algorithm which determines unique decipherability would be worthwhile.
tails = Æ
Generate-tails
So O(n2l2)
The tails in case 1 are obvious. Those generated in case 2 are of the form ts = c or cs = t where a new tail is {s} . s is indeed a tail here.
Proof by induction.
base case: let t, a tail M(t) = minimal n+m s.t. c1...cmt = c¢1...c¢n
when M(t) = n+m = 2 , c1t = c1¢ which is covered by the first step in the algorithm.
Inductive case: M(t) > 2 with c1...cmt = c1¢...cn¢ . Assume pt = cn¢