\documentclass[12pt]{article}
\usepackage{pseudocode}
\usepackage[margin=1.1in]{geometry}

\begin{document}

\section*{Psuedocode Examples}

Examples using \texttt{pseudocode.sty}

\subsection*{Example of Sequences and Sets}
\begin{tabular}{ll}
a sequence: & 
  $A = \cseq{7,2,5,4}$\\
its length & 
  $|A| \Rightarrow 4$ \\
the second element & 
  $A_2 \Rightarrow 5$ \\
a range & 
  $\cidx{4}{7} 
  \Rightarrow 
  \cseq{4,5,6,7}$ \\
a subsequence & 
  $A \cidx{1}{3} 
  \Rightarrow 
  \cseq{2,5,4}$ \\
map over a sequence:  & 
  $\cseq{x^2 : x \in A}
  \Rightarrow 
  \cseq{49,4,25,16}$\\
filter over a sequence: & 
  $\cseqf{x \in A}{x > 3} 
  \Rightarrow 
  \cseq{7,5,4}$\\[.1in]
a set: & 
  $B = \cset{3,5,1,6,8}$ \\
filter over a set: & 
  $\csetf{x \in B}{x > 3} 
  \Rightarrow 
  \cset{5,6,8}$\\[.1in]
a table: & 
  $C = \cset{a \mapsto 4, b \mapsto 1, c \mapsto 8}$ \\
map and filter over a table: & 
  $\csetf{x \mapsto y^2 : (x \mapsto y) \in C}{y > 3} 
  \Rightarrow 
  \cset{a \mapsto 16, b \mapsto 64}$
\end{tabular}

\subsection*{Example Code}
\begin{lstlisting}
function greedyApproxSS$(S)$ =
  if $|S| = 1$ then $S_0$
  else
    let
      val $O$ = $\csetf{(\mbox{overlap}(s_i, s_j), s_i, s_j) 
                        : s_i \in S, s_j \in S}{
                       s_i \neq s_j}$
      val $(o,s_i,s_j)$ = $\argmax_{(x,\_,\_) \in O} x$
      val $s_k$ = join$(s_i,s_j)$
      val $S'$ = $(\{s_k\} \cup S) \setminus \{s_i,s_j\}$
    in
      greedyApproxSS$(S')$
    end
\end{lstlisting} 

\noindent
Another example:

\begin{lstlisting}
function mcss$(S)$ =
  case (showt $S$) 
    of EMPTY => $-\infty$
     | ELT$(x)$ => $x$
     | NODE$(L, R)$ => 
        let
          val $(m_L, m_R)$ = (mcss$(L)$ || mcss$(R)$)
          val $m_a$ = bestAcross$(L, R)$
        in 
          $\max\{m_L, m_R, m_A\}$
        end
\end{lstlisting} 

\end{document}
