day 11 2/16/98 ``Shouldn't ask questions that you don't want to know the answer.''

1.  Dynamic programming

1.1  Optimal Binary Search Trees

1.1.1 given

1.1.2 analysis

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)

1.1.3 definitions

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 .

Cost(T) = Cost(Tik-1)+wik-1+Cost(Tkj)+wkj+pk

= Cost(Tik-1)+Cost(Tkj)+wij

Then,

cij = mini+1 < k < j{Cik+1+Ckj}+wij

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.

1.2  Huffman codes

1.2.1 givens

1.2.2 Unique decipherability

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.

1.2.3 Algorithm

tails = Æ

Generate-tails

  1. "ci&cj i ¹ j .

  1. "c,"t Î tails

  1. return ``C is UD''

1.2.4 Analysis

So O(n2l2)

1.2.5 Algorithm correctness

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¢


File translated from TEX by TTH, version 1.30.