{VERSION 6 0 "IBM INTEL NT" "6.0" }
{USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0
1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0
0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }
{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1
257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0
0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0
0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }
{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal
" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1
1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1
-1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 3 0 }1 0 0 -1 -1 -1 0 0 0
0 0 0 -1 0 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18
0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "War
ning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 0 }0
0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "
" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0
0 -1 0 }{PSTYLE "Maple Output" -1 12 1 {CSTYLE "" -1 -1 "Times" 1 12
0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Tit
le" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1
}3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 1 {CSTYLE ""
-1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2
2 0 1 }}
{SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 36 "CS 300 (Spring 2003-04) A
ssignment 1" }}{PARA 19 "" 0 "" {TEXT -1 17 "Jeremy R. Johnson" }}
{PARA 0 "" 0 "" {TEXT -1 73 "Due by the start of class on Thursday Apr
il 29 by the beginning of class." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}
{PARA 0 "" 0 "" {TEXT -1 626 "The purpose of this assignment is to fur
ther familiarize students with using Maple to empirically explore prob
lems and use its mathematical computation capabilities to analyze prob
lems. In addition students will get comfortable programming in Maple \+
and in particular using recursive data structures and algorithms. In \+
this assignment, the exploration involves an application to the analys
is of algorithms and the generation of combinatorial objects. The alg
orithms involved center around binary search trees and more general tr
ees. There are two major parts, each worth 50 points. Each part has \+
a sequence of subproblems." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0
"" 0 "" {TEXT -1 225 "The assignment should be submitted using the sub
mit command available on CS department Unix machines. You will need t
o get an MCS account if you do not already have one. See the departme
nt web page to activate your account." }}{PARA 0 "" 0 "" {TEXT -1 0 "
" }}{PARA 0 "" 0 "" {TEXT -1 158 "Make sure that you add comments abou
t your experiments, observations, and conclusions. Other guidelines f
or assignments will be posted on the class web page." }}{PARA 0 "" 0 "
" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 66 "Question 1 (50
points): Priority Queues using Binary Search Trees" }}{PARA 0 "" 0 "
" {TEXT -1 181 "In this question, you will investigate the average and
worst case behavior of a priority queue (supports Max, Insert, and De
leteMax functions) implemented using binary search trees." }}{PARA 0 "
" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 259 19 "Part a) [10 point
s]" }{TEXT -1 262 " Write a recursive procedure, MaxBST, to compute t
he maximum element of a binary search tree. Use the recursive list da
ta structure in Lecture 5 to represent binary search trees. Make sure
that you test your procedure. You must show the tests you performed
." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 ""
{TEXT 256 19 "Part b) [15 points]" }{TEXT -1 311 ". Empirically explo
re the maximum and average number of recursive calls to MaxBST (includ
ing the top-level call). You should determine the average and maximum
number of calls for a sequence of small n by exhaustively examining a
ll binary search trees (see Lecture 5). Produce a sequence of values \+
for n=1..7." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "
" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "
" {TEXT 260 20 "Part c) [15 points] " }{TEXT -1 485 "Empirically explo
re the growth rate of the average and maximum number of calls to MaxBS
T. In this question you will need data for a sequence of larger n (e.
g. n = 10, 20, ..., 100) and consequently will not be able to compute \+
exactly the result by exhaustively examing all binary search trees. I
nstead you should choose a random sample (see Lecture 5) of binary sea
rch trees. Compare the sequences you obtained to known functions of n
and see what you can say about the growth rate." }}{PARA 0 "" 0 ""
{TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0
"" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 261 21 "Part d) [10 poi
nts] " }{TEXT -1 277 "Derive recurrence relations for the average and \+
maximum number of calls to MaxBST as a function of the number of eleme
nts, n, in the tree. Use Maple's rsolve function to find a closed for
m to these recurrences and check your result against the empirical dat
a in parts b and c." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0
"> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 61 "Q
uestion 2 (50 points): Generating and Counting Ordered Trees" }}{PARA
0 "" 0 "" {TEXT -1 479 "In this question you will write recursive Mapl
e functions to count the number and generate ordered trees with n elem
ents. By an ordered tree, we mean a rooted tree where internal nodes \+
have an ordered sequence of an arbitrary number of children. You shou
ld use a recursive list data structure to represent the trees. Nodes \+
in the tree should be labled by a positive integer equal to the number
of children in the subtree rooted at that node. Here is the recursiv
e definition:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 ""
{TEXT -1 26 "Tree ::= [count, children]" }}{PARA 0 "" 0 "" {TEXT -1
120 "count is the number of nodes in the tree and children is a list, \+
possibly empty, of Trees that are the subtrees of Tree." }}{PARA 0 ""
0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 52 "E.G. [6, [ [1,[]], \+
[3,[ [1,[]],[1,[]] ], [1,[]] ] ]" }}{PARA 0 "" 0 "" {TEXT -1 21 "is th
e tree 6" }}{PARA 0 "" 0 "" {TEXT -1 29 " /
| \\" }}{PARA 0 "" 0 "" {TEXT -1 27 " 1 3 1
" }}{PARA 0 "" 0 "" {TEXT -1 25 " / \\" }}{PARA
0 "" 0 "" {TEXT -1 25 " 1 1" }}{PARA 0 "" 0 ""
{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 257 19 "Part a) [
30 points]" }{TEXT -1 499 " Write and test a recursive Maple procedur
e to generate all trees with n children. Hint: for a tree with n nod
es, you will need to generate all possible lists of children whose sum
of nodes is equal to n-1. This is a composition of n-1. A compositi
on of a positive integer m is a list of positive integers [m1.,,,,mt] \+
whose sum is equal to m. Maple has a command in the combinat package \+
to generate all compositions of an integer into a specified number of \+
parts (i.e. for a given value of t)." }}{PARA 0 "" 0 "" {TEXT -1 0 ""
}}{PARA 0 "" 0 "" {TEXT -1 236 "Use your procedure to generate all tre
es for a sequence of small values of n. You should check your results
by hand for small n. You should write a procedure to print trees so \+
that you can easily visualize the results (see Lecture 5)." }}{PARA 0
"" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "with
(combinat);" }}{PARA 7 "" 1 "" {TEXT -1 67 "Warning, the protected nam
e Chi has been redefined and unprotected\n" }}{PARA 12 "" 1 ""
{XPPMATH 20 "6#7C%$ChiG%%bellG%)binomialG%)cartprodG%*characterG%'choo
seG%,compositionG%)conjpartG%+decodepartG%+encodepartG%*fibonacciG%*fi
rstpartG%)graycodeG%)inttovecG%)lastpartG%,multinomialG%)nextpartG%)nu
mbcombG%)numbcompG%)numbpartG%)numbpermG%*partitionG%(permuteG%)powers
etG%)prevpartG%)randcombG%)randpartG%)randpermG%-setpartitionG%*stirli
ng1G%*stirling2G%(subsetsG%)vectointG" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 17 "composition(4,4);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#
<#7&\"\"\"F%F%F%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "GenTree
s := proc(n) option remember;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 26 " \+
local T, children, part;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 32 " if n \+
= 0 then return [[]]; fi;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 36 " if n
= 1 then return [[1,[]]]; fi;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 24 " \+
for k from 1 to n-1 do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " spli
ts := composition(n-1,k);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " fo
r part in splits do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " map(Ge
nTrees,part);" }}{PARA 7 "" 1 "" {TEXT -1 32 "Warning, premature end o
f input\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "
" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 258 19 "Part b) [20 point
s]" }{TEXT -1 482 " Write a recursive Maple function to count the numb
er of trees with n nodes. This procedure should not actually generate
all trees, though it can have the same recursive structure as your pr
ocedure in Part a. You can use the nops function to count the number \+
of trees generated in part a for small n and use these counts to check
your results in Part b. Use your function to count the number of t
rees to empirically investigate the growth rate of the number of trees
of size n." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "
" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}
{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}{MARK "2" 0 }
{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }