Problem Set 3: Tries and LZW Compression
Due Thursday, February 26
For this problem set, you are to turn in an overview document covering Part 2. The overview document
should be composed as described in
Overview Requirements
. You should read this document carefully.
We have provided an
example overview document
written as if for
Problem Set 2
from CS 312, Spring
2008. Submission in PDF is preferred; however, you can also submit your overview document as a .doc or a
.txt file.
In particular, starting with this problem set, it's
your
job to convince
us
that your code works, by describing
your implementation and by presenting a testing strategy, test cases, and results.
Part 1 : Substitution Model
Find an expression that, when substituted for the ??, will cause the following function for the given input to
evaluate to 42. Show the evaluation using the substitution model. You may omit minor substitutions, but be
sure to show all the main steps. At an absolute minimum, show each step before and after a recursive call.
Steps that create new global bindings should also be shown
let rec
zardoz l =
match
l
with
[]
> ??
 h::t > (h (zardoz t))
in
let rec
f n =
if
n=1
then
1
else
n*f(n1)+n+2
in
zardoz [(
fun
n > 7*n); f];;
To do:
turn in the solution under Substition Model in CMS. Submission is allowed in .pdf, .doc, or .txt.
Please include your name and netid in your solution.
Part 2: Tries
Several algorithms, including the compression algorithms and string matching algorithms, make use of
maps where the keys are strings (or sequences) of values of a certain type. A
trie
(pronounced "try") or
prefix tree
is an efficient data structure for implementing the map ADT for this kind of map. The set of
possible elements in the key strings is referred to as the
alphabet
of the trie.
A trie is a tree structure whose edges are labeled with the elements of the alphabet. Each node can have up
to N children, where N is the size of the alphabet. Nodes correspond to strings of elements of the alphabet.
More precisely, each node corresponds to the sequence of elements traversed on the path from the root to
that node. The map binds a string
s
to a value
v
by storing the value
v
in the node of
s
. The advantage of
this scheme is that if efficiently represents common string prefixes, and lookups or inserts are achieved
using quick searches starting from the root.
Suppose we want to build a map from strings of ASCII characters to integer codes. In this case, edges are
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
labeled with ASCII characters, and integer codes are stored in (some of) the nodes. Here is an example:
The above trie describes the map
{"to">7, "tea">3, "ten">12, "in">5, "inn">9}
. The
values (shown in blue) are stored in the nodes. Note that nodes might not have values. For instance the
node that corresponds to string
"te"
doesn't have a value. Hence,
"te"
is not in the map.
This is the end of the preview.
Sign up
to
access the rest of the document.
 '07
 GIAMBATTISTA,A
 translation table, LZW compression

Click to edit the document details