This document contains information concerning the conduct of the mid-term examination, and some sample questions, representative of those that will be set.
The mid-term examination for this course will be held, as advertised, on Thursday, April 14th, during the normal lecture period.
The examination will contain one short question (worth 5 marks), and three longer questions. You should attempt the short question, and only two of the three longer questions, each of which will be worth 10 marks.
val a = 1;
val b = 2; fun f a = a + b; val b = 3; f b; |
Suppose we are interested in trees where an internal node at level n always has exactly n children. Define a function check : ’a Tree ->bool that checks whether a given tree has this property.
signature EQueue =
sig type Item type Queue val empty : Queue val enq : (Item * Queue) -> Queue val deq : Queue -> (Item * Queue) val menq: (Item list * Queue) -> Queue end |
An implementation of a stack, including this operation, uses the type declaration
type Queue = Item list list
|
the operations empty and menq are implemented as follows:
val empty = []
fun menq(items, q) = items :: q |
fun enq(item, []) =
| enq(item, (h :: t)) = fun deq((h :: t) :: r) = | deq([] :: r) = | deq [] = |
for this implementation?
fun union(a, []) = a
| union([], b) = b | union(ah :: at, bh :: bt) = if ah < bh then ah :: union(at, bh :: bt) else if ah = bh then ah :: union(at, bt) else bh :: union(ah :: at, bt) |
(C) Michael Fourman 1994-2006