UNIVERSITY OF MALTA
FACULTY OF INFORMATION & COMMUNICATION
TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE
June 2015 Examination Session
2 June 2015
14:30–16:35
CPS1005: Discrete Mathematics for Computing Science
Stationery: Calculators are allowed.
Instructions:
1. The first 5 (five) minutes of the exam is reading time.
2. This is an OPEN BOOK exam. Students are allowed to use course
notes, books, scientific calculators and cigarette lighters. No other
electronic / smart devices are permitted. Unless otherwise stated, theorems and lemmata proved in the course textbook may be quoted.
3. Answer any two of the following three questions. Each question carries
50 marks. If more than two questions are answered, only the first two
questions in the booklet will be taken into consideration.
page 1 of 3
PTO
1. Consider the following type definition representing trees with sets of
numbers stored at the leaves and with predicates over numbers at the
nodes:
BatchTree ::= Leaf PN
| Node (N → B) × BatchTree × BatchTree
The element insertion function traverses the tree taking the left or right
branch of a node based on the predicate, until it reaches a leaf, where
it places the inserted item:
def
= Leaf(N
∪ {n})
Node(insert(n, l), r)
def
insert(n, Node(c, l, r)) =
Node(l, insert(n, r))
insert(n, Leaf N )
if c(n)
otherwise
(a) Give the inductive principle for the type BatchTree.
(b) Define a function empty, which takes a BatchTree and returns the
same tree with all leaves having the empty set.
(c) Prove that ∀t : BatchTree · ∀n : N · empty(t) = empty(insert(n, t)).
2. Consider the following definition:
def
iseven(Zero)
= true
def
iseven(Succ(n)) = ¬(iseven(n))
isodd (Zero)
isodd (Succ(n))
def
= false
= ¬(isodd (n))
def
Using the definitions and theorems about addition given in the textbook, prove that ∀n : N · iseven(Succ(n)) = isodd (n). Hence or
otherwise prove that ∀n : N · iseven(n) = ¬isodd (n).
3. A numbered Kripke structure is a form of a graph with (i) no information on the edges; and (ii) additional numeric information stored in the
vertices. Formally, a Kripke structure M is a 4-tuple hV, E, I, πi. Just
as in a graph, V is the set of vertices, and E ⊆ V × V is the set of
page 2 of 3
PTO
edges between vertices. In addition, I ⊆ V is the set of initial vertices
of M , from where any traversal of the graph can start, and π ∈ V → N
assigns a numeric value to each vertex.
(a) A sequence of vertices vs is said to be a valid path in M if all
sequential pairs of vertices in the sequence are joined by an edge
in M . Using standard sequence operators, formally define the
predicate path M (vs) which is true if and only if vs is a valid path
in M . Hint: Use pattern-matching on vs.
(b) A vertex v is said to be reachable in M if there is a valid path
starting from an initial vertex of M and finishing in v. Formally
define reachable(M ) which returns the set of all reachable vertices
in M .
(c) A numbered Kripke structure is said to be odd if all reachable
vertices are associated (using π) with an odd number. Formally
define this notion.
(d) Given a set of bad numbers B, a numbered Kripke structure is said
to be correct if no vertices associated (via π) with a bad number
are reachable. Formally define correct M (B) which is true if and
only if M is correct with respect to B.
page 3 of 3
end of paper
© Copyright 2026 Paperzz