\documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}
\usepackage{fancyvrb}
\usepackage{relsize}

\begin{document}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: {\bf Work only on this sheet} (on both sides, if needed); do not
turn in any supplementary sheets of paper. There is actually plenty of room
for your answers, as long as you organize yourself BEFORE starting writing.
In order to get full credit, {\bf SHOW YOUR WORK}.

{\bf 1.}  This problem concerns the Curses PLN.

\begin{itemize}

\item [(a)] (10) What member variable of the {\bf curses} class stores the
number of rows in the window?

\end{itemize}

The remaining parts of this problem concern the {\bf psax} program.

\begin{itemize}

\item [(b)] (10) The window will initially be blank.  Give the number of the
line of code at which the window ceases to be all blank.

\item [(c)] (10) Give a function call that could be inserted into {\bf psax}
in order to move the highlighting to the top row of the window.

\end{itemize}

{\bf 2.} (5) Fill in the blank with an official term from our course: Consider
the port scanner example.  We could have each thread check b consecutive
ports, rather than just 1, for better efficiency due to reduced thread
startup overhead.  But if we make b too large, we will likely have a
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
problem.

{\bf 3.} (20) I wrote a program that I use to produce roll sheets for each
class I teach.  It inputs the student list I receive from the Registrar,
and outputs the same list but with only some information retained.
Specifically, the input variables are number on the roll sheet (1, 2, 3,
...), student ID, surname, first name, middle name if any, class (FR,
SO, JR, SR, etc.), major (ECSE, LCSI, etc.), enrollment status (RE for
enrolled, WL for wait list, etc.) and UCD e-mail address (e.g. jjones).
I retain just the last name, first name, middle name if any, class level and
major.  The input file name is the first command line argument.  The
output file name will have the form GradesXXX.txt, e.g GradesS07.txt;
the XXX part is the second command line argument.  Fill in the blanks in
my code:

\begin{Verbatim}[fontsize=\relsize{-2}]
import _____________
infilename = open(sys.argv[1])
outfilename = ______________________
g = open(_____________________)
for l in infilename:
   w = l.split()
   del w[len(w)_________________]
   del w[:2]
   g.________________
\end{Verbatim}

{\bf 4.} (15) Suppose we wish to be able to sort strings, with the sort
criterion being dictionary order within length.  In other words, the
primary sort criterion is string length, and the secondary criterion is
ordinary string ordering.  For example, 'eas' would be considered $>$
'et' while the latter would be $<$ 'eu'.  Fill in the blanks for the
function {\bf llcmp()}, to be used as an argument to {\bf sort()} in the
{\bf list} class:

\begin{Verbatim}[fontsize=\relsize{-2}]
def llcmp(x,y):
   if x == y: return 0
   elif len(x) != len(y): return _________________________
   elif ________________________: __________________________
   return 1
\end{Verbatim}

Note:  The member functions {\bf \_\_lt\_\_()}, {\bf \_\_le\_\_()}, etc.
in the {\bf string} class do the ordinary compare, in which for
instance 'eas' $<$ 'eb'.

{\bf 5.} (10) Our program will generate a random matrix.  The command-line
arguments consist of the number of rows and columns.  Fill in the blank:

\begin{Verbatim}[fontsize=\relsize{-2}]
(rows,cols) = _________________________________________________
\end{Verbatim}

{\bf 6.} (20) This problem deals with our homework program which implemented
the A Priori algorithm for rule finding in data mining.  Recall that the
rules were stored in a dictionary, with the keys being tuples of the
form (antecedents, consequent) and the values being tuples of the form
(support, confidence).  For instance, if the value for the key (0,2,7)
is (0.24, 0.66), then the rule 0,2 =$>$ 7 has support 0.24 and confidence
0.66.  Say the variable for our dictionary is {\bf ruled}.  

Say we also have a dictionary {\bf freqd} containing all itemsets with
frequency at least equal to {\bf minsupp $\times$ minconf}, the product
of the minimum support and confidence levels.  The keys are tuples for
the itemsets and the values are the support levels.  So for example if
we have a key (3,4) with value 0.51, then 0.51 of the records in the
database contain both items 3 and 4.

But support and confidence may not be the only criteria which are of
practical value.  Suppose for instance the singleton (7) has support
(0.60).  Then knowing that 0 and 2 occurred makes 7 only slightly more
likely to occur than if we don't know whether 0 and 2 occurred.  The
likelihood ratio here is 0.66/0.60 = 1.10.  This is called the {\it
lift}.  

The code below will compute a list {\bf z} of all rules in {\bf ruled} that
have lift at least equal to {\bf minlift}.

\begin{Verbatim}[fontsize=\relsize{-2}]
z = []
for (rule,suppconf) in ruled:
   if ____________________________:
      z.append(rule)
\end{Verbatim}

{\bf 1.a} {\bf curses.LINES}

{\bf 1.b} 65 (when {\bf refresh()} is called)

{\bf 1.c} {\bf updown(-gb.winrow}

{\bf 2.}  load balancing

{\bf 3.}

\begin{Verbatim}[fontsize=\relsize{-2}]
sys
Grades + sys.argv[2] + '.txt'
outfilename, 'w'
-2:
write(outfilename,' '.join(w) + '\n'
\end{Verbatim}

{\bf 4.}

\begin{Verbatim}[fontsize=\relsize{-2}]
len(x) - len(y)
x.__lt__(y): return -1
\end{Verbatim}

{\bf 5.}

\begin{Verbatim}[fontsize=\relsize{-2}]
(int(sysargv[1]), int(sysargv[2]))
\end{Verbatim}

or

\begin{Verbatim}[fontsize=\relsize{-2}]
map(int,sysargv[1:])
\end{Verbatim}

{\bf 6.}

\begin{Verbatim}[fontsize=\relsize{-2}]
suppconf[1] >= minlift * freqd[rule[-1]:]
\end{Verbatim}



\end{document}


